package me.zacharias.compadability.mixins;

import me.zacharias.compadability.Config;
import me.zacharias.compadability.register.Modules;
import mekanism.api.gear.IModule;
import mekanism.api.gear.IModuleHelper;
import mekanism.common.capabilities.fluid.item.FluidTankSpec;
import mekanism.common.config.MekanismConfig;
import mekanism.common.item.gear.ItemMekaSuitArmor;
import mekanism.common.registries.MekanismModules;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.material.Fluids;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(ItemMekaSuitArmor.class)
public class MixinItemMekaSuitArmor {

    @Final
    @Shadow
    private List<FluidTankSpec> fluidTankSpecs;


    @Inject(method = "<init>(Lnet/minecraft/world/item/ArmorItem$Type;Lnet/minecraft/world/item/Item$Properties;)V",
            at = @At("TAIL"))
    public void onConstructor(ArmorItem.Type armorType, Item.Properties properties, CallbackInfo ci)
    {
        if (armorType == ArmorItem.Type.HELMET) {
            // Add a water-fill-only tank using the same rates/capacity as the nutritional tank.
            // The predicate fluid -> fluid.is(Fluids.WATER) accepts vanilla water.
            // stack -> true means the tank is allowed for all stacks; change to a module-check
            // if you want it gated by a module (e.g. use hasModule(stack, MekanismModules.SOME_MODULE)).
            fluidTankSpecs.add(FluidTankSpec.createFillOnly(
                    Config.MAX_WATER_UNIT_TRANSFER,
                    Config.MAX_WATER_UNIT_CONTENT,
                    fluid -> fluid.is(Fluids.WATER),
                    stack -> {
                        IModule<?> module = IModuleHelper.INSTANCE.getModule(stack, Modules.WATER_PURIFIED_DRINKING_UNIT);
                        return module == null || module.getInstalledCount() > 0;
                    }
            ));
        }
    }
}
