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 java.util.List;
import net.minecraft.network.chat.Component;
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;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

/**
 * Base class for blindfold items (classic blindfold, mask, hood, etc.)
 * These items obstruct a player's vision when equipped.
 *
 * Based on original ItemBlindfold from 1.12.2
 *
 */
public abstract class ItemBlindfold
    extends Item
    implements IBondageItem, IHasBlindingEffect, IAdjustable, ILockable
{

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

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

    @Override
    public void appendHoverText(
        ItemStack stack,
        @Nullable Level level,
        List<Component> tooltip,
        TooltipFlag flag
    ) {
        super.appendHoverText(stack, level, tooltip, flag);
        appendLockTooltip(stack, tooltip);
    }

    /**
     * All blindfolds can be adjusted to better fit player skins.
     * @return true - blindfolds support position adjustment
     */
    @Override
    public boolean canBeAdjusted() {
        return true;
    }

    /**
     * Called when player right-clicks another entity with this blindfold.
     * Allows putting blindfold 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.isBlindfolded(),
            (state, item) -> state.equip(BodyRegionV2.EYES, item),
            (state, item) ->
                state.replaceEquipment(BodyRegionV2.EYES, item, false),
            (p, t) ->
                SystemMessageManager.sendToTarget(
                    p,
                    t,
                    SystemMessageManager.MessageCategory.BLINDFOLDED
                ),
            "ItemBlindfold"
        );
    }

    // ILockable implementation inherited from interface default methods
}
