package com.tiedup.remake.client.animation;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
 * Central registry for player animation state tracking.
 *
 * <p>Holds per-player state maps that were previously scattered across
 * AnimationTickHandler. Provides a single clearAll() entry point for
 * world unload cleanup.
 */
@OnlyIn(Dist.CLIENT)
public final class AnimationStateRegistry {

    /** Track last tied state per player */
    static final Map<UUID, Boolean> lastTiedState = new ConcurrentHashMap<>();

    /** Track last animation ID per player to avoid redundant updates */
    static final Map<UUID, String> lastAnimId = new ConcurrentHashMap<>();

    private AnimationStateRegistry() {}

    public static Map<UUID, Boolean> getLastTiedState() {
        return lastTiedState;
    }

    public static Map<UUID, String> getLastAnimId() {
        return lastAnimId;
    }

    /**
     * Clear all animation-related state in one call.
     * Called on world unload to prevent memory leaks and stale data.
     */
    public static void clearAll() {
        // Animation state tracking
        lastTiedState.clear();
        lastAnimId.clear();

        // Animation managers
        BondageAnimationManager.clearAll();
        PendingAnimationManager.clearAll();

        // V2 animation context system (clearAll chains to ContextAnimationFactory.clearCache)
        com.tiedup.remake.client.gltf.GltfAnimationApplier.clearAll();

        // Render state
        com.tiedup.remake.client.animation.render.DogPoseRenderHandler.clearState();

        // NPC animation state
        com.tiedup.remake.client.animation.tick.NpcAnimationTickHandler.clearAll();

        // MCA animation cache
        com.tiedup.remake.client.animation.tick.MCAAnimationTickCache.clear();
    }
}
