package com.tiedup.remake.dialogue.conversation;

import com.tiedup.remake.personality.PersonalityType;

/**
 * Represents the effects of a conversation topic on an NPC's state.
 * Effects are applied with personality modifiers.
 *
 */
public record TopicEffect(
    /** Mood change (-20 to +20) */
    float moodChange
) {
    // --- Static Factory Methods for Standard Topics ---

    public static TopicEffect compliment() {
        return new TopicEffect(5f);
    }

    public static TopicEffect comfort() {
        return new TopicEffect(10f);
    }

    public static TopicEffect praise() {
        return new TopicEffect(3f);
    }

    public static TopicEffect scold() {
        return new TopicEffect(-5f);
    }

    public static TopicEffect threaten() {
        return new TopicEffect(-8f);
    }

    public static TopicEffect tease() {
        return new TopicEffect(0f);
    }

    public static TopicEffect howAreYou() {
        return new TopicEffect(1f);
    }

    public static TopicEffect whatsWrong() {
        return new TopicEffect(2f);
    }

    // --- Effect Application Methods ---

    /**
     * Apply personality modifier to this effect.
     * Different personalities react differently to topics.
     *
     * @param personality The NPC's personality
     * @param topic The topic being used
     * @return Modified TopicEffect
     */
    public TopicEffect withPersonalityModifier(
        PersonalityType personality,
        ConversationTopic topic
    ) {
        float moodMult = 1.0f;

        switch (personality) {
            case MASOCHIST -> {
                if (
                    topic == ConversationTopic.SCOLD ||
                    topic == ConversationTopic.THREATEN
                ) {
                    moodMult = -0.5f;
                }
            }
            case SUBMISSIVE -> {
                if (topic == ConversationTopic.PRAISE) {
                    moodMult = 1.5f;
                }
            }
            case PLAYFUL -> {
                if (topic == ConversationTopic.TEASE) {
                    moodMult = 3.0f;
                }
            }
            case TIMID -> {
                if (topic == ConversationTopic.COMFORT) {
                    moodMult = 1.5f;
                }
            }
            case GENTLE -> {
                if (
                    topic == ConversationTopic.COMPLIMENT ||
                    topic == ConversationTopic.COMFORT
                ) {
                    moodMult = 1.3f;
                }
            }
            case PROUD -> {
                if (topic == ConversationTopic.COMPLIMENT) {
                    moodMult = 0.5f;
                }
            }
            default -> {
                // No special handling
            }
        }

        return new TopicEffect(this.moodChange * moodMult);
    }

    /**
     * Apply effectiveness multiplier (from topic fatigue).
     *
     * @param effectiveness Multiplier (0.2 to 1.0)
     * @return Scaled TopicEffect
     */
    public TopicEffect withEffectiveness(float effectiveness) {
        return new TopicEffect(this.moodChange * effectiveness);
    }

    /**
     * Get the base effect for a conversation topic.
     *
     * @param topic The topic
     * @return Base TopicEffect
     */
    public static TopicEffect forTopic(ConversationTopic topic) {
        return switch (topic) {
            case COMPLIMENT -> compliment();
            case COMFORT -> comfort();
            case PRAISE -> praise();
            case SCOLD -> scold();
            case THREATEN -> threaten();
            case TEASE -> tease();
            case HOW_ARE_YOU -> howAreYou();
            case WHATS_WRONG -> whatsWrong();
            default -> neutral();
        };
    }

    /**
     * Create a neutral effect (no changes).
     */
    public static TopicEffect neutral() {
        return new TopicEffect(0f);
    }

    /**
     * Check if this effect has any significant changes.
     *
     * @return true if any value is non-zero
     */
    public boolean hasEffect() {
        return moodChange != 0;
    }

    /**
     * Get a descriptive string of the effect for debugging.
     *
     * @return Human-readable effect description
     */
    public String toDebugString() {
        if (moodChange != 0) {
            return "Mood:" + (moodChange > 0 ? "+" : "") + moodChange;
        }
        return "";
    }
}
