package common.item.tool;

import common.entity.npc.EntityNPC;
import common.item.ItemStack;
import common.model.Model;
import common.model.ModelProvider;
import common.potion.Potion;
import common.potion.PotionEffect;
import common.potion.PotionHelper;
import common.world.World;

public class ItemFishFood extends ItemFood
{
    private final boolean cooked;
    private final FishType type;

    public ItemFishFood(boolean cooked, FishType type)
    {
        super(0, false);
        this.cooked = cooked;
        this.type = type;
    }
    
    public FishType getType() {
    	return this.type;
    }
    
    public boolean isCooked() {
    	return this.cooked;
    }

    public int getHealAmount(ItemStack stack)
    {
        return this.cooked && this.type.canCook() ? this.type.getCookedHealAmount() : this.type.getUncookedHealAmount();
    }

    public String getPotionEffect(ItemStack stack)
    {
        return this.type == ItemFishFood.FishType.PUFFERFISH ? PotionHelper.pufferfishEffect : null;
    }

    protected void onFoodEaten(ItemStack stack, World worldIn, EntityNPC player)
    {
        if (this.type == ItemFishFood.FishType.PUFFERFISH)
        {
            player.addEffect(new PotionEffect(Potion.POISON, 1200, 3));
            player.addEffect(new PotionEffect(Potion.NAUSEA, 300, 1));
        }

        super.onFoodEaten(stack, worldIn, player);
    }

    public String getDisplay(ItemStack stack)
    {
        return (this.type.canCook() ? (this.cooked ? "Gebratener " : "Roher ") : "") + this.type.getDisplay();
    }

    public Model getModel(ModelProvider provider, String name) {
    	return provider.getModel(this.getTransform(), (this.cooked ? "cooked_" : "") + this.type.getName());
    }

    public static enum FishType
    {
        COD("cod", 0, "Kabeljau", 2, 5),
        SALMON("salmon", 1, "Lachs", 2, 6),
        CLOWNFISH("clownfish", 2, "Clownfisch", 1),
        PUFFERFISH("pufferfish", 3, "Kugelfisch", 1);

        private final int meta;
        private final String name;
        private final String display;
        private final int uncookedHealAmount;
        private final int cookedHealAmount;
        private boolean cookable = false;

        private FishType(String name, int meta, String display, int uncookedHeal, int cookedHeal)
        {
            this.name = name;
            this.meta = meta;
            this.display = display;
            this.uncookedHealAmount = uncookedHeal;
            this.cookedHealAmount = cookedHeal;
            this.cookable = true;
        }

        private FishType(String name, int meta, String display, int uncookedHeal)
        {
            this.name = name;
            this.meta = meta;
            this.display = display;
            this.uncookedHealAmount = uncookedHeal;
            this.cookedHealAmount = 0;
            this.cookable = false;
        }

        public int getMetadata()
        {
            return this.meta;
        }

        public String getDisplay()
        {
            return this.display;
        }

        public String getName()
        {
            return this.name;
        }

        public int getUncookedHealAmount()
        {
            return this.uncookedHealAmount;
        }

        public int getCookedHealAmount()
        {
            return this.cookedHealAmount;
        }

        public boolean canCook()
        {
            return this.cookable;
        }
    }
}
