package com.tiedup.remake.state.hosts;

import com.tiedup.remake.state.IBondageState;
import com.tiedup.remake.state.ICaptor;
import com.tiedup.remake.state.PlayerCaptorManager;
import java.util.UUID;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

/**
 * Core host interface for PlayerBindState components.
 * Provides access to player data and coordination methods.
 *
 * Thread Safety: Methods accessing volatile fields are thread-safe.
 */
public interface IPlayerBindStateHost {
    // ========== Entity Access ==========

    /**
     * Get the player entity associated with this state.
     * @return The player entity
     */
    Player getPlayer();

    /**
     * Get the player's UUID.
     * @return The player's unique identifier
     */
    UUID getPlayerUUID();

    /**
     * Get the current level/world the player is in.
     * @return The player's current level
     */
    Level getLevel();

    /**
     * Check if this instance is on the client side.
     * @return true if client-side, false if server-side
     */
    boolean isClientSide();

    /**
     * Get the IBondageState interface for this player state.
     * Used when components need to pass the player state to other systems.
     * @return This instance cast to IBondageState
     */
    IBondageState getKidnapped();

    // ========== Lifecycle ==========

    /**
     * Check if the player is currently online.
     * @return true if player is online
     */
    boolean isOnline();

    /**
     * Set the player's online status.
     * @param online true if player is online
     */
    void setOnline(boolean online);

    // ========== Network Sync (Centralized) ==========

    /**
     * Sync clothes configuration to all tracking clients.
     * Used when clothes are equipped/changed.
     */
    void syncClothesConfig();

    /**
     * Sync enslavement/captivity state to all clients.
     * Used when capture/free state changes.
     */
    void syncEnslavement();

    // ========== System Access ==========

    /**
     * Get the current captor (master) of this player.
     * @return The captor, or null if not captive
     */
    ICaptor getCaptor();

    /**
     * Set the captor for this player.
     * @param captor The new captor, or null to clear
     */
    void setCaptor(ICaptor captor);

    /**
     * Get the captor manager (for when player acts as captor).
     * @return The captor manager
     */
    PlayerCaptorManager getCaptorManager();

    // ========== State Queries ==========

    /**
     * Check if player is tied up (has bind equipment).
     * @return true if player has bind
     */
    boolean isTiedUp();

    /**
     * Check if player has a collar equipped.
     * @return true if player has collar
     */
    boolean hasCollar();

    // ========== Struggle State (Volatile Wrapper) ==========

    /**
     * Set struggle animation state (server-side).
     * Thread-safe (volatile field).
     * @param struggling True to start animation, false to stop
     * @param tick Current game time tick
     */
    void setStruggling(boolean struggling, long tick);

    /**
     * Set struggle animation flag (client-side only).
     * Thread-safe (volatile field).
     * Does NOT update timer - server manages timer.
     * @param struggling True if struggling
     */
    void setStrugglingClient(boolean struggling);

    /**
     * Check if player is currently playing struggle animation.
     * Thread-safe (volatile field).
     * @return true if struggling
     */
    boolean isStruggling();

    /**
     * Get the tick when struggle animation started.
     * Thread-safe (volatile field).
     * @return Start tick
     */
    long getStruggleStartTick();
}
