package net.wayward_realms.waywardprofessions;

import net.wayward_realms.waywardlib.professions.ToolType;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.ConfigurationSerializable;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;

public class ProfessionInfo implements ConfigurationSerializable {

    private Map<ToolType, Integer> maxToolDurability = new EnumMap<>(ToolType.class);
    private Map<Material, Integer> craftEfficiency = new EnumMap<>(Material.class);
    private Map<Material, Integer> miningEfficiency = new EnumMap<>(Material.class);
    private int brewingEfficiency;

    public int getMaxToolDurability(ToolType type) {
        if (maxToolDurability.get(type) == null) return 0;
        return maxToolDurability.get(type);
    }

    public void setMaxToolDurability(ToolType type, int durability) {
        maxToolDurability.put(type, durability);
    }

    public int getCraftEfficiency(Material material) {
        if (craftEfficiency.get(material) == null) return 0;
        return craftEfficiency.get(material);
    }

    public void setCraftEfficiency(Material material, int efficiency) {
        craftEfficiency.put(material, Math.min(efficiency, 100));
    }

    public int getMiningEfficiency(Material material) {
        if (miningEfficiency.get(material) == null) return 0;
        return miningEfficiency.get(material);
    }

    public void setMiningEfficiency(Material material, int efficiency) {
        miningEfficiency.put(material, Math.min(efficiency, 100));
    }

    public int getBrewingEfficiency() {
        return brewingEfficiency;
    }

    public void setBrewingEfficiency(int efficiency) {
        this.brewingEfficiency = Math.min(efficiency, 100);
    }

    @Override
    public Map<String, Object> serialize() {
        Map<String, Object> serialised = new HashMap<>();
        serialised.put("max-tool-durability", maxToolDurability);
        serialised.put("craft-efficiency", craftEfficiency);
        serialised.put("mining-efficiency", miningEfficiency);
        serialised.put("brewing-efficiency", brewingEfficiency);
        return serialised;
    }

    public static ProfessionInfo deserialize(Map<String, Object> serialised) {
        ProfessionInfo deserialised = new ProfessionInfo();
        deserialised.maxToolDurability = (Map<ToolType, Integer>) serialised.get("max-tool-durability");
        deserialised.craftEfficiency = (Map<Material, Integer>) serialised.get("craft-efficiency");
        deserialised.miningEfficiency = (Map<Material, Integer>) serialised.get("mining-efficiency");
        deserialised.brewingEfficiency = (int) serialised.get("brewing-efficiency");
        return deserialised;
    }
}

@@ -1874,24 +1874,272 @@
 ashMap%3C%3E();%0A
+        Map%3CString, Integer%3E maxToolDurabilityNames = new HashMap%3C%3E();%0A        for (Map.Entry%3CToolType, Integer%3E entry : maxToolDurability.entrySet()) %7B%0A            maxToolDurabilityNames.put(entry.getKey().toString(), entry.getValue());%0A        %7D%0A
         seri
@@ -2185,27 +2185,274 @@
 olDurability
+Names
 );%0A
+        Map%3CString, Integer%3E craftEfficiencyNames = new HashMap%3C%3E();%0A        for (Map.Entry%3CMaterial, Integer%3E entry : craftEfficiency.entrySet()) %7B%0A            craftEfficiencyNames.put(entry.getKey().toString(), entry.getValue());%0A        %7D%0A
         seri
@@ -2489,35 +2489,285 @@
  craftEfficiency
+Names
 );%0A
+        Map%3CString, Integer%3E miningEfficiencyNames = new HashMap%3C%3E();%0A        for (Map.Entry%3CMaterial, Integer%3E entry : miningEfficiency.entrySet()) %7B%0A            miningEfficiencyNames.put(entry.getKey().toString(), entry.getValue());%0A        %7D%0A
         serialis
@@ -2802,32 +2802,37 @@
 miningEfficiency
+Names
 );%0A        seria
@@ -3068,54 +3068,60 @@
     
-deserialised.maxToolDurability = (Map%3CToolType
+for (Map.Entry%3CString, Integer%3E entry : ((Map%3CString
 , In
@@ -3165,18 +3165,36 @@
 bility%22)
-;%0A
+).entrySet()) %7B%0A    
         
@@ -3210,39 +3210,153 @@
 sed.
-craftEfficiency = (Map%3CMaterial
+maxToolDurability.put(ToolType.valueOf(entry.getKey()), entry.getValue());%0A        %7D%0A        for (Map.Entry%3CString, Integer%3E entry : ((Map%3CString
 , In
@@ -3389,34 +3389,52 @@
 aft-efficiency%22)
-;%0A
+).entrySet()) %7B%0A    
         deserial
@@ -3438,22 +3438,21 @@
 ialised.
-mining
+craft
 Efficien
@@ -3457,72 +3457,315 @@
 ency
- = (Map%3CMaterial, Integer%3E) serialised.get(%22mining-efficiency%22);
+.put(Material.getMaterial(entry.getKey()), entry.getValue());%0A        %7D%0A        for (Map.Entry%3CString, Integer%3E entry : ((Map%3CString, Integer%3E) serialised.get(%22mining-efficiency%22)).entrySet()) %7B%0A            deserialised.miningEfficiency.put(Material.getMaterial(entry.getKey()), entry.getValue());%0A        %7D
 %0A   

Fix serialisation of profession info