package com.tiedup.remake.personality;

import com.tiedup.remake.v2.bondage.BindModeHelper;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.SwordItem;

/**
 * Tool modes that determine NPC behavior during FOLLOW command.
 * The item in the NPC's main hand determines their active behavior.
 */
public enum ToolMode {
    /** No tool or unrecognized item - passive following */
    PASSIVE,

    /** SwordItem - attack hostile mobs near master */
    ATTACK,

    /** PickaxeItem - mine stone/ores near master */
    MINING,

    /** AxeItem - chop wood near master */
    WOODCUTTING,

    /** ARMS-region bondage item - capture untied damsels */
    CAPTURE;

    /**
     * Detect tool mode from main hand item.
     *
     * @param mainHand Item in main hand
     * @return Detected tool mode
     */
    public static ToolMode fromItem(ItemStack mainHand) {
        if (mainHand.isEmpty()) {
            return PASSIVE;
        }

        var item = mainHand.getItem();

        if (item instanceof SwordItem) {
            return ATTACK;
        }
        if (item instanceof PickaxeItem) {
            return MINING;
        }
        if (item instanceof AxeItem) {
            return WOODCUTTING;
        }
        if (BindModeHelper.isBindItem(mainHand)) {
            return CAPTURE;
        }

        return PASSIVE;
    }

    /**
     * Get translation key for this mode.
     *
     * @return Translation key
     */
    public String getTranslationKey() {
        return "toolmode." + this.name().toLowerCase();
    }
}
