package me.km.items;

import java.util.function.Supplier;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.Items;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.LazyValue;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public enum ModArmorMaterial implements IArmorMaterial {
    COPPER("km:copper", 9, new int[]{1, 4, 5, 1}, 20, SoundEvents.ITEM_ARMOR_EQUIP_CHAIN, 0.0f, () -> Ingredient.fromItems(ModItems.copperIngot)),
    BRONZE("km:bronze", 13, new int[]{2, 5, 6, 2}, 3, SoundEvents.ITEM_ARMOR_EQUIP_CHAIN, 0.0f, () -> Ingredient.fromItems(ModItems.bronzeIngot)),
    STRAW("km:straw", 3, new int[]{1, 1, 1, 1}, 3, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, 0.0f, () -> Ingredient.fromItems(Items.WHEAT)),
    CYLINDER("km:cylinder", 3, new int[]{1, 1, 1, 1}, 3, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, 0.0f, () -> Ingredient.fromItems(Items.STRING)),
    SILK("km:silk", 3, new int[]{1, 1, 1, 1}, 3, SoundEvents.ITEM_ARMOR_EQUIP_LEATHER, 0.0f, () -> Ingredient.fromItems(Items.STRING));

    private static final int[] MAX_DAMAGE_ARRAY = new int[]{
        13, 15, 16, 11
    };

    private final String name;
    private final int maxDamageFactor;
    private final int[] damageReductionAmountArray;
    private final int enchantability;
    private final SoundEvent soundEvent;
    private final float toughness;
    private final LazyValue<Ingredient> repairMaterial;

    private ModArmorMaterial(String name, int maxDamageFactor, int[] damageReduction, int enchantability, SoundEvent se, float toughness, Supplier<Ingredient> repairMaterial) {
        this.name = name;
        this.maxDamageFactor = maxDamageFactor;
        this.damageReductionAmountArray = damageReduction;
        this.enchantability = enchantability;
        this.soundEvent = se;
        this.toughness = toughness;
        this.repairMaterial = new LazyValue<>(repairMaterial);
    }

    @Override
    public int getDurability(EquipmentSlotType slotIn) {
        return MAX_DAMAGE_ARRAY[slotIn.getIndex()] * this.maxDamageFactor;
    }

    @Override
    public int getDamageReductionAmount(EquipmentSlotType slotIn) {
        return this.damageReductionAmountArray[slotIn.getIndex()];
    }

    @Override
    public int getEnchantability() {
        return this.enchantability;
    }

    @Override
    public SoundEvent getSoundEvent() {
        return this.soundEvent;
    }

    @Override
    public Ingredient getRepairMaterial() {
        return this.repairMaterial.getValue();
    }

    @OnlyIn(Dist.CLIENT)
    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public float getToughness() {
        return this.toughness;
    }
}
