package com.bekvon.bukkit.residence;

import java.io.File;
import java.util.Map;

import org.bukkit.Location;
import org.bukkit.entity.Player;

import com.bekvon.bukkit.residence.permissions.PermissionManager;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.FlagPermissions;
import com.bekvon.bukkit.residence.protection.LeaseManager;
import com.bekvon.bukkit.residence.protection.PermissionListManager;
import com.bekvon.bukkit.residence.protection.ResidenceManager;
import com.bekvon.bukkit.residence.protection.WorldFlagManager;

import pw.yumc.Residence.ResidenceMain;
import pw.yumc.Residence.chat.ChatManager;
import pw.yumc.Residence.economy.EconomyInterface;
import pw.yumc.Residence.economy.TransactionManager;
import pw.yumc.Residence.economy.rent.RentManager;
import pw.yumc.Residence.itemlist.WorldItemManager;
import pw.yumc.Residence.manager.ConfigManager;
import pw.yumc.Residence.manager.EntityManager;
import pw.yumc.Residence.selection.SelectionManager;
import pw.yumc.Residence.text.Language;
import pw.yumc.Residence.text.help.HelpEntry;

public class Residence {
    static ResidenceMain instance;

    public Residence(final ResidenceMain instance) {
        Residence.instance = instance;
    }

    public static ChatManager getChatManager() {
        return instance.getChatManager();
    }

    public static ConfigManager getConfigManager() {
        return instance.getConfigManager();
    }

    public static File getDataLocation() {
        return instance.getDataFolder();
    }

    public static Map<String, String> getDeleteConfirm() {
        return instance.getDeleteConfirm();
    }

    public static EconomyInterface getEconomyManager() {
        return instance.getEconomyManager();
    }

    public static EntityManager getEntityManager() {
        return instance.getEntityManager();
    }

    public static HelpEntry getHelppages() {
        return instance.getHelppages();
    }

    public static WorldItemManager getItemManager() {
        return instance.getItemManager();
    }

    public static Language getLanguage() {
        if (instance.getLanguage() == null) {
            instance.setLanguage(new Language());
        }
        return instance.getLanguage();
    }

    public static LeaseManager getLeaseManager() {
        return instance.getLeaseManager();
    }

    public static PermissionListManager getPermissionListManager() {
        return instance.getPermissionListManager();
    }

    public static PermissionManager getPermissionManager() {
        return instance.getPermissionManager();
    }

    public static FlagPermissions getPermsByLoc(final Location loc) {
        final ClaimedResidence res = getResidenceManager().getByLoc(loc);
        if (res != null) {
            return res.getPermissions();
        }
        return getWorldFlags().getPerms(loc.getWorld().getName());
    }

    public static FlagPermissions getPermsByLocForPlayer(final Location loc, final Player player) {
        final ClaimedResidence res = getResidenceManager().getByLoc(loc);
        if (res != null) {
            return res.getPermissions();
        } else if (player != null) {
            return getWorldFlags().getPerms(player);
        } else {
            return getWorldFlags().getPerms(loc.getWorld().getName());
        }
    }

    public static RentManager getRentManager() {
        return instance.getRentManager();
    }

    public static ResidenceManager getResidenceManager() {
        return instance.getResidenceManager();
    }

    public static SelectionManager getSelectionManager() {
        return instance.getSelectionManager();
    }

    public static TransactionManager getTransactionManager() {
        return instance.getTransactionManager();
    }

    public static WorldFlagManager getWorldFlags() {
        return instance.getWorldFlags();
    }

    public static boolean isResAdminOn(final Player player) {
        if (instance.getResadminToggle().contains(player.getName())) {
            return true;
        }
        return false;
    }

    public static boolean isResAdminOn(final String player) {
        if (instance.getResadminToggle().contains(player.toLowerCase())) {
            return true;
        }
        return false;
    }

    public static boolean isUseWorldEdit() {
        return instance.isUseWorldEdit();
    }
}
