package engine.gameManager;

import engine.Enum;
import engine.math.Vector3fImmutable;
import engine.objects.Guild;
import engine.objects.PlayerCharacter;
import engine.objects.Regions;

import java.util.*;

public class LoreMineManager {

    //Saetor Allowed Charters:
    //BARBARIAN
    //MILITARY
    //RANGER
    //AMAZON
    //WIZARD
    //MERCENARY
    //THIEVES
    //SCOURGE
    //UNHOLY

    public static final Map<Enum.GuildType, List<String>> GUILD_RACES = new HashMap<>();
    public static final Map<Enum.GuildType, List<String>> GUILD_CLASSES = new HashMap<>();
    public static final Map<Enum.GuildType, Boolean> GUILD_GENDER_RESTRICTION = new HashMap<>();

    static {
        GUILD_RACES.put(Enum.GuildType.CATHEDRAL, Arrays.asList("Aelfborn", "Centaur", "Elf", "Half Giant", "Human"));
        GUILD_CLASSES.put(Enum.GuildType.CATHEDRAL, Arrays.asList("Bard", "Channeler", "Crusader", "Nightstalker", "Prelate", "Priest", "Scout", "Sentinel"));

        GUILD_RACES.put(Enum.GuildType.MILITARY, Arrays.asList("Centaur", "Half Giant", "Human", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.MILITARY, Arrays.asList("Bard", "Priest", "Scout", "Warlock", "Warrior", "Wizard"));

        GUILD_RACES.put(Enum.GuildType.TEMPLE, Arrays.asList("Half Giant", "Human"));
        GUILD_CLASSES.put(Enum.GuildType.TEMPLE, Arrays.asList("Assassin", "Bard", "Channeler", "Confessor", "Nightstalker", "Priest", "Scout", "Templar"));

        GUILD_RACES.put(Enum.GuildType.BARBARIAN, Arrays.asList("Aelfborn", "Half Giant", "Human", "Minotaur", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.BARBARIAN, Arrays.asList("Barbarian", "Bard", "Doomsayer", "Fury", "Priest", "Scout", "Thief", "Warrior"));

        GUILD_RACES.put(Enum.GuildType.RANGER, Arrays.asList("Aelfborn", "Elf", "Half Giant", "Human", "Shade", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.RANGER, Arrays.asList("Bard", "Channeler", "Druid", "Priest", "Ranger", "Scout", "Warrior"));

        GUILD_RACES.put(Enum.GuildType.AMAZON, Arrays.asList("Aelfborn", "Elf", "Half Giant", "Human", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.AMAZON, Arrays.asList("Bard", "Druid", "Fury", "Huntress", "Priest", "Scout", "Warrior", "Wizard"));
        GUILD_GENDER_RESTRICTION.put(Enum.GuildType.AMAZON, true); // Female only

        GUILD_RACES.put(Enum.GuildType.NOBLE, Arrays.asList("Aelfborn", "Half Giant", "Human"));
        GUILD_CLASSES.put(Enum.GuildType.NOBLE, Arrays.asList("Assassin", "Bard", "Channeler", "Priest", "Scout", "Thief", "Warlock", "Warrior", "Wizard"));

        GUILD_RACES.put(Enum.GuildType.WIZARD, Arrays.asList("Aelfborn", "Elf", "Human", "Nephilim", "Shade", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.WIZARD, Arrays.asList("Assassin", "Bard", "Channeler", "Doomsayer", "Fury", "Necromancer", "Priest", "Warlock", "Wizard"));

        GUILD_RACES.put(Enum.GuildType.MERCENARY, Arrays.asList("Aelfborn", "Aracoix", "Half Giant", "Human", "Shade", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.MERCENARY, Arrays.asList("Assassin", "Bard", "Priest", "Scout", "Thief", "Warlock", "Warrior"));

        GUILD_RACES.put(Enum.GuildType.THIEVES, Arrays.asList("Aelfborn", "Aracoix", "Elf", "Human", "Irekei", "Nephilim", "Shade", "Vampire", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.THIEVES, Arrays.asList("Assassin", "Barbarian", "Bard", "Priest", "Scout", "Thief", "Wizard"));

        GUILD_RACES.put(Enum.GuildType.DWARF, Arrays.asList("Dwarf"));
        GUILD_CLASSES.put(Enum.GuildType.DWARF, Arrays.asList("Crusader", "Prelate", "Priest", "Sentinel", "Warrior"));

        GUILD_RACES.put(Enum.GuildType.HIGHCOURT, Arrays.asList("Elf", "Minotaur"));
        GUILD_CLASSES.put(Enum.GuildType.HIGHCOURT, Arrays.asList("Assassin", "Bard", "Channeler", "Druid", "Necromancer", "Priest", "Ranger", "Scout", "Thief", "Warrior", "Wizard"));

        GUILD_RACES.put(Enum.GuildType.VIRAKT, Arrays.asList("Irekei"));
        GUILD_CLASSES.put(Enum.GuildType.VIRAKT, Arrays.asList("Assassin", "Bard", "Channeler", "Fury", "Huntress", "Nightstalker", "Priest", "Ranger", "Scout", "Thief", "Warrior", "Wizard"));

        GUILD_RACES.put(Enum.GuildType.SCOURGE, Arrays.asList("Aelfborn", "Human", "Minotaur", "Nephilim", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.SCOURGE, Arrays.asList("Bard", "Channeler", "Doomsayer", "Priest", "Scout", "Warrior", "Wizard"));

        GUILD_RACES.put(Enum.GuildType.KHREE, Arrays.asList("Aracoix"));
        GUILD_CLASSES.put(Enum.GuildType.KHREE, Arrays.asList("Assassin", "Barbarian", "Bard", "Huntress", "Priest", "Ranger", "Scout", "Thief", "Warlock", "Warrior"));

        GUILD_RACES.put(Enum.GuildType.CENTAUR, Arrays.asList("Centaur"));
        GUILD_CLASSES.put(Enum.GuildType.CENTAUR, Arrays.asList("Barbarian", "Crusader", "Druid", "Huntress", "Prelate", "Priest", "Ranger", "Sentinel", "Warrior"));

        GUILD_RACES.put(Enum.GuildType.UNHOLY, Arrays.asList("Human", "Shade", "Vampire", "Saetor"));
        GUILD_CLASSES.put(Enum.GuildType.UNHOLY, Arrays.asList("Assassin", "Channeler", "Necromancer", "Priest", "Scout", "Thief", "Warlock", "Warrior", "Wizard"));
    }

    public static void AuditPlayer(PlayerCharacter pc){
        Guild nation = pc.guild.getNation();
        int charterID = nation.getCharter();
        if(!validForCharter(pc,charterID)){
            //bounce out to SDR
            Vector3fImmutable bounceLoc = Vector3fImmutable.getRandomPointOnCircle(ZoneManager.getZoneByUUID(656).getLoc(),30f);
            pc.setLoc(bounceLoc);
            MovementManager.translocate(pc, bounceLoc, Regions.GetRegionForTeleport(ZoneManager.getZoneByUUID(656).getLoc()));
            ChatManager.chatSystemInfo(pc, "You Failed To Meet Lore Requirements");
        }
    }

    public static boolean validForCharter(PlayerCharacter pc, int charterID) {
        if(pc.getPromotionClass() == null)
            return false;
        Enum.GuildType guildType = Enum.GuildType.getGuildTypeFromInt(charterID);

        // Define the races and classes for each GuildType


        // Get the allowed races and classes for this guildType
        List<String> allowedRaces = GUILD_RACES.getOrDefault(guildType, Collections.emptyList());
        List<String> allowedClasses = GUILD_CLASSES.getOrDefault(guildType, Collections.emptyList());

        // Validate player's race and class
        if (!allowedRaces.contains(pc.getRace().getName()) || !allowedClasses.contains(pc.getPromotionClass().getName())) {
            return false;
        }

        // Gender restriction check for AMAZON
        if (guildType.equals(Enum.GuildType.AMAZON) && pc.isMale() && pc.getRaceID() != 1999) {
            return false;
        }

        return true;
    }

}
