package moe.oko.opennaw.util;

import moe.oko.opennaw.model.Nation;
import net.luckperms.api.model.group.Group;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

public class NationHandler {

    private HashMap<String, Nation> nations = new HashMap<>();

    public void addNation(String name, Group group) {
        nations.put(name, new Nation(name, group));
    }

    public void removeNation(String name) {
        nations.remove(name);
    }

    public Group getNationGroup(String name) {
        return nations.get(name).getGroup();
    }

    public boolean isPlayerInNation(Player player, Nation nation) {
        return nation.getPlayerMap().containsKey(player.getUniqueId());
    }

    public Nation getNationByPlayer(UUID uuid) {
        for(var nation : nations.values()) {
            if(nation.getPlayerMap().containsKey(uuid)) {
                return nation;
            }
        }
        return null;
    }

    public List<String> getNationList() {
        List<String> nationList = new ArrayList<String>();
        for (Nation nation : nations.values()) {
            nationList.add(nation.getName());
        }
        return nationList;
    }
}
