namespace Theriapolis.Core.Rules.Combat;

/// <summary>
/// Mutable per-turn state for the active combatant: action / bonus action /
/// reaction availability and remaining movement budget. The
/// <see cref="Encounter"/> rebuilds this when each new turn begins; the
/// <see cref="Resolver"/> consumes resources as the combatant uses them.
///
/// Phase 5 M4 tracks the booleans but doesn't enforce them inside Resolver
/// (callers can attack twice in a turn if they want — useful for tests).
/// M5 introduces per-action-cost gating in the live PlayScreen wrapper.
/// </summary>
public struct Turn
{
    public int  CombatantId;
    public bool ActionAvailable;
    public bool BonusActionAvailable;
    public bool ReactionAvailable;
    public int  RemainingMovementFt;

    public static Turn FreshFor(int combatantId, int speedFt) => new()
    {
        CombatantId          = combatantId,
        ActionAvailable      = true,
        BonusActionAvailable = true,
        ReactionAvailable    = true,
        RemainingMovementFt  = speedFt,
    };

    public void ConsumeAction()      => ActionAvailable      = false;
    public void ConsumeBonusAction() => BonusActionAvailable = false;
    public void ConsumeReaction()    => ReactionAvailable    = false;
    public void ConsumeMovement(int feet)
    {
        RemainingMovementFt -= feet;
        if (RemainingMovementFt < 0) RemainingMovementFt = 0;
    }
}
