package com.tiedup.remake.items.base;

import com.tiedup.remake.core.SystemMessageManager;
import com.tiedup.remake.util.EquipmentInteractionHelper;
import com.tiedup.remake.v2.BodyRegionV2;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

/**
 * Base class for mittens items.
 * These items block hand interactions (mining, placing, using items) when equipped.
 *
 *
 * Restrictions when wearing mittens:
 * - Cannot mine/break blocks
 * - Cannot place blocks
 * - Cannot use items
 * - Cannot attack (0 damage punch allowed)
 *
 * Allowed:
 * - Push buttons/levers
 * - Open doors
 */
public abstract class ItemMittens
    extends Item
    implements IBondageItem, ILockable
{

    public ItemMittens(Properties properties) {
        super(properties);
    }

    @Override
    public BodyRegionV2 getBodyRegion() {
        return BodyRegionV2.HANDS;
    }

    /**
     * Called when player right-clicks another entity with these mittens.
     * Allows putting mittens on tied-up entities (Players and NPCs).
     */
    @Override
    public InteractionResult interactLivingEntity(
        ItemStack stack,
        Player player,
        LivingEntity target,
        InteractionHand hand
    ) {
        return EquipmentInteractionHelper.equipOnTarget(
            stack,
            player,
            target,
            state -> state.hasMittens(),
            (state, item) -> state.equip(BodyRegionV2.HANDS, item),
            (state, item) ->
                state.replaceEquipment(BodyRegionV2.HANDS, item, false),
            (p, t) ->
                SystemMessageManager.sendToTarget(
                    p,
                    t,
                    SystemMessageManager.MessageCategory.MITTENS_ON
                ),
            "ItemMittens"
        );
    }

    // ILockable implementation inherited from interface default methods
}
