package com.tiedup.remake.client.animation.context;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
 * Represents the current player/NPC posture and action state for animation selection.
 * Determines which base body posture animation to play.
 *
 * <p>Each context maps to a GLB animation name via a prefix + variant scheme:
 * <ul>
 *   <li>Prefix: "Sit", "Kneel", "Sneak", "Walk", or "" (standing)</li>
 *   <li>Variant: "Idle" or "Struggle"</li>
 * </ul>
 * The {@link GlbAnimationResolver} uses these to build a fallback chain
 * (e.g., SitStruggle -> Struggle -> SitIdle -> Idle).</p>
 */
@OnlyIn(Dist.CLIENT)
public enum AnimationContext {
    STAND_IDLE("stand_idle", false),
    STAND_WALK("stand_walk", false),
    STAND_SNEAK("stand_sneak", false),
    STAND_STRUGGLE("stand_struggle", true),
    SIT_IDLE("sit_idle", false),
    SIT_STRUGGLE("sit_struggle", true),
    KNEEL_IDLE("kneel_idle", false),
    KNEEL_STRUGGLE("kneel_struggle", true),

    // Movement style contexts
    SHUFFLE_IDLE("shuffle_idle", false),
    SHUFFLE_WALK("shuffle_walk", false),
    HOP_IDLE("hop_idle", false),
    HOP_WALK("hop_walk", false),
    WADDLE_IDLE("waddle_idle", false),
    WADDLE_WALK("waddle_walk", false),
    CRAWL_IDLE("crawl_idle", false),
    CRAWL_MOVE("crawl_move", false);

    private final String animationSuffix;
    private final boolean struggling;

    AnimationContext(String animationSuffix, boolean struggling) {
        this.animationSuffix = animationSuffix;
        this.struggling = struggling;
    }

    /**
     * Suffix used as key for context animation JSON files (e.g., "stand_idle").
     */
    public String getAnimationSuffix() {
        return animationSuffix;
    }

    /**
     * Whether this context represents an active struggle state.
     */
    public boolean isStruggling() {
        return struggling;
    }

    /**
     * Get the GLB animation name prefix for this context's posture.
     * Used by the fallback chain in {@link GlbAnimationResolver}.
     *
     * @return "Sit", "Kneel", "Sneak", "Walk", or "" for standing
     */
    public String getGlbContextPrefix() {
        return switch (this) {
            case SIT_IDLE, SIT_STRUGGLE -> "Sit";
            case KNEEL_IDLE, KNEEL_STRUGGLE -> "Kneel";
            case STAND_SNEAK -> "Sneak";
            case STAND_WALK -> "Walk";
            case STAND_IDLE, STAND_STRUGGLE -> "";
            case SHUFFLE_IDLE, SHUFFLE_WALK -> "Shuffle";
            case HOP_IDLE, HOP_WALK -> "Hop";
            case WADDLE_IDLE, WADDLE_WALK -> "Waddle";
            case CRAWL_IDLE, CRAWL_MOVE -> "Crawl";
        };
    }

    /**
     * Get the GLB animation variant name: "Struggle" or "Idle".
     */
    public String getGlbVariant() {
        return switch (this) {
            case STAND_STRUGGLE, SIT_STRUGGLE, KNEEL_STRUGGLE -> "Struggle";
            case STAND_WALK, SHUFFLE_WALK, HOP_WALK, WADDLE_WALK -> "Walk";
            case CRAWL_MOVE -> "Move";
            default -> "Idle";
        };
    }
}
