package com.tiedup.remake.compat.mca.personality;

/**
 * TiedUp-specific traits that combine with MCA base personalities.
 *
 * <p>These traits are stored in the MCA villager's capability (NBT)
 * and can be assigned via command or acquired naturally through gameplay.
 *
 * <p>Multipliers combine with MCA personality: {@code final = personality * trait}
 *
 * <h3>Trait Acquisition:</h3>
 * <ul>
 *   <li>NONE - Default, no special trait</li>
 *   <li>MASO - Rare discovery or assigned (enjoys bondage)</li>
 *   <li>REBELLIOUS - After repeated failed captures or strong personality</li>
 *   <li>BROKEN - After very long captivity without liberation</li>
 *   <li>TRAINED - After prolonged captivity with good treatment (positive mood)</li>
 * </ul>
 */
public enum TiedUpTrait {
    /** No special trait - uses base personality only */
    NONE("none", 1.0f, 1.0f, 0),

    /** Masochistic - enjoys being restrained */
    MASO("maso", 0.3f, 2.0f, +5),

    /** Rebellious - always fights back */
    REBELLIOUS("rebellious", 1.8f, 0.3f, -5),

    /** Broken - has given up resisting (acquired only) */
    BROKEN("broken", 0.1f, 3.0f, 0),

    /** Trained - has accepted their situation (acquired only) */
    TRAINED("trained", 0.5f, 1.5f, +1);

    private final String id;
    private final float struggleMultiplier;
    private final float complianceMultiplier;
    private final int moodModifier;

    TiedUpTrait(String id, float struggle, float compliance, int mood) {
        this.id = id;
        this.struggleMultiplier = struggle;
        this.complianceMultiplier = compliance;
        this.moodModifier = mood;
    }

    public String getId() {
        return id;
    }

    /**
     * Get struggle multiplier (combines with personality).
     */
    public float getStruggleMultiplier() {
        return struggleMultiplier;
    }

    /**
     * Get compliance multiplier (combines with personality).
     */
    public float getComplianceMultiplier() {
        return complianceMultiplier;
    }

    /**
     * Get mood modifier when tied.
     * Added to personality's base mood change.
     */
    public int getMoodModifier() {
        return moodModifier;
    }

    /**
     * Check if this trait makes the villager enjoy bondage.
     */
    public boolean enjoysBondage() {
        return moodModifier > 0;
    }

    /**
     * Check if this trait represents a broken will.
     */
    public boolean isBroken() {
        return this == BROKEN;
    }

    /**
     * Find trait by ID string (case-insensitive).
     *
     * @param id The trait ID (e.g., "maso", "trained")
     * @return The matching trait, or NONE if not found
     */
    public static TiedUpTrait fromId(String id) {
        if (id == null) return NONE;
        for (TiedUpTrait t : values()) {
            if (t.id.equalsIgnoreCase(id)) {
                return t;
            }
        }
        return NONE;
    }

    /**
     * Calculate combined struggle multiplier with personality.
     */
    public static float getCombinedStruggle(
        MCAPersonality personality,
        TiedUpTrait trait
    ) {
        return (
            personality.getStruggleMultiplier() * trait.getStruggleMultiplier()
        );
    }

    /**
     * Calculate combined compliance multiplier with personality.
     */
    public static float getCombinedCompliance(
        MCAPersonality personality,
        TiedUpTrait trait
    ) {
        return (
            personality.getComplianceMultiplier() *
            trait.getComplianceMultiplier()
        );
    }

    /**
     * Calculate combined mood change when tied.
     */
    public static int getCombinedMoodTied(
        MCAPersonality personality,
        TiedUpTrait trait
    ) {
        return personality.getBaseMoodTied() + trait.getMoodModifier();
    }
}
