package com.ilummc.talent.data;

import com.google.common.io.Files;
import com.google.gson.Gson;
import com.ilummc.talent.Talent;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Set;

public class Config {

    private static Config instance;

    private boolean enableRaces, enableClasses;
    private Map<String, Race> races;
    private Map<String, Class> classes;
    private Map<String, WorldSetting> worlds;
    private Naming naming;
    private boolean enableScriptSkills, enableScriptPrecompile, enableScriptPlaceholder;

    public static boolean isScriptPlaceholderEnabled() {
        return instance.enableScriptPlaceholder;
    }

    public static boolean isScriptPrecompileEnabled() {
        return instance.enableScriptPrecompile;
    }

    public static boolean isScriptSkillsEnabled() {
        return instance.enableScriptSkills;
    }

    public static Naming getNaming() {
        return instance.naming;
    }

    public static Set<String> getRaces() {
        return instance.races.keySet();
    }

    public static Set<String> getClasses() {
        return instance.classes.keySet();
    }

    public static boolean isClassesEnabled() {
        return instance.enableClasses;
    }

    public static boolean isRacesEnabled() {
        return instance.enableRaces;
    }

    public static WorldSetting getWorldSetting(String name) {
        return instance.worlds.get(name);
    }

    public static Class getClass(String name) {
        return instance.classes.get(name);
    }

    public static Race getRace(String name) {
        return instance.races.get(name);
    }

    public static Config getInstance() {
        return instance;
    }

    public static void load() {
        File yml = new File(Talent.instance.getDataFolder(), "config.yml");
        if (!yml.exists())
            Talent.instance.saveResource("config.yml", true);
        try {
            Map map = (Map) new Yaml().load(Files.toString(yml, Charset.forName("utf-8")));
            instance = new Gson().fromJson(new Gson().toJson(map), Config.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static class Race {
        public String name;
        public RaceBonus bonus;
        public boolean hide;
    }

    public static class RaceBonus {
        public String life, mana, spd, str, con, dex, per, intl, wil, mag, charm;
    }

    public static class Class {
        public String name;
        public ClassBonus bonus;
        public boolean hide;
    }

    public static class ClassBonus {
        public String str, con, dex, per, intl, wil, mag, charm;
    }

    public static class WorldSetting {
        private Long seed;

        public Long getSeed() {
            return seed;
        }
    }

    public static class Naming {
        public String healthPoint, manaPoint, staminaPoint, sleep, food, life, mana, speed, strength, constitution,
                dexterity, perception, intellect, willpower, magic, charm, dodge, protection, sanity, potential, karma,
                luck, regeneration,
                melee, accurancy, range, expbonus, lifesteal, bound, levelcap, classcap, racecap, attributecap,
                durability, weaponspeed, reflection,
                fire, fireDamage, firePercentage, fireResistance, fireReflection, cold, coldDamage, coldPercentage,
                coldResistance, coldReflection, lightning, lightningDamage, lightningPercentage, lightningResistance,
                lightningReflection, darkness, darknessDamage, darknessPercentage, darknessResistance,
                darknessReflection, mind, mindDamage, mindPercentage, mindResistance, mindReflection, poison,
                poisonDamage, poisonPercentage, poisonResistance, poisonReflection, nether, netherDamage,
                netherPercentage, netherResistance, netherReflection, chaos, chaosDamage, chaosPercentage,
                chaosResistance, chaosReflection, magicElement, magicDamage, magicPercentage, magicResistance,
                magicReflection;
    }

}