namespace Theriapolis.Core.Rules.Stats;

/// <summary>
/// Status effects applied during combat or by environment. Phase 5 ships
/// the most common subset; the enum is open-ended for additions in later
/// phases without renumbering existing values.
/// </summary>
public enum Condition : byte
{
    None         = 0,
    Prone        = 1,
    Frightened   = 2,
    Restrained   = 3,
    Grappled     = 4,
    Dazed        = 5,
    Blinded      = 6,
    Stunned      = 7,
    Unconscious  = 8,
    Charmed      = 9,
    Poisoned     = 10,
    Deafened     = 11,
    Invisible    = 12,
    Petrified    = 13,
    Incapacitated = 14,
    /// <summary>1..6 levels per d20; tracked separately on Character.ExhaustionLevel rather than as a binary flag.</summary>
    Exhausted    = 15,
}

public static class ConditionExtensions
{
    public static Condition FromJson(string raw) => raw.ToLowerInvariant() switch
    {
        "none"          => Condition.None,
        "prone"         => Condition.Prone,
        "frightened"    => Condition.Frightened,
        "restrained"    => Condition.Restrained,
        "grappled"      => Condition.Grappled,
        "dazed"         => Condition.Dazed,
        "blinded"       => Condition.Blinded,
        "stunned"       => Condition.Stunned,
        "unconscious"   => Condition.Unconscious,
        "charmed"       => Condition.Charmed,
        "poisoned"      => Condition.Poisoned,
        "deafened"      => Condition.Deafened,
        "invisible"     => Condition.Invisible,
        "petrified"     => Condition.Petrified,
        "incapacitated" => Condition.Incapacitated,
        "exhausted"     => Condition.Exhausted,
        _ => throw new ArgumentException($"Unknown condition: '{raw}'"),
    };
}
