namespace Theriapolis.Core.Entities;

/// <summary>
/// Phase 6.5 M6 — bounded vocabulary of "scent reads" surfaced by
/// Scent-Broker abilities (Scent Literacy at L1, Scent Mastery /
/// <c>master_nose</c> at L11). Each tag is a short, in-fiction
/// observation a Scent-Broker can pick out of an NPC's scent profile —
/// recent activity, faction affiliation, distress markers.
///
/// Per the Phase 6.5 plan §3.2: bounded enum on purpose. Phase 8's full
/// scent-propagation simulation can extend the vocabulary; Phase 6.5
/// keeps the set small and the population path simple (auto-derived from
/// faction id + a small set of runtime triggers — see
/// <see cref="NpcActor.ComputeScentTags"/>).
///
/// Display priority is the enum order: lower-numbered tags win when
/// truncating to a single read for L1 Scent Literacy. Faction-affiliation
/// tags lead because they're the most narratively meaningful (Lacroix
/// reads as "Maw-affiliated" before "recently killed", because the latter
/// is generic brigand flavour).
/// </summary>
public enum ScentTag : byte
{
    None = 0,

    // ── Faction-affiliation reads (priority 1–8) ─────────────────────────
    /// <summary>The NPC carries the scent of Maw chemistry / contact.</summary>
    MawAffiliated             = 1,
    /// <summary>Inheritor pheromone-marker / ration scent.</summary>
    InheritorAffiliated       = 2,
    /// <summary>Thorn Council chemical signatures.</summary>
    ThornCouncilAffiliated    = 3,
    /// <summary>Covenant Enforcer protocol scent (uniform launderings, sigil oils).</summary>
    CovenantEnforcerAffiliated = 4,
    /// <summary>Hybrid Underground safe-house scent traces.</summary>
    HybridUndergroundAffiliated = 5,
    /// <summary>Unsheathed (hybrid activist) chemical markers.</summary>
    UnsheathedAffiliated      = 6,
    /// <summary>Merchant-guild handshake oils — well-traveled, much-greeted.</summary>
    MerchantAffiliated        = 7,

    // ── Runtime-derived reads (priority 16+) ─────────────────────────────
    /// <summary>Has killed something recently (within ~1 hour). Set on melee kill.</summary>
    RecentlyKilled       = 16,
    /// <summary>Carries combat-distress markers — fleeing or near-death.</summary>
    Frightened           = 17,
    /// <summary>Carries contraband (pheromone vials, deep-cover masks, faction sigils).</summary>
    CarriesContraband    = 18,
    /// <summary>Wounded — current HP &lt; 50%.</summary>
    Wounded              = 19,
}

public static class ScentTagExtensions
{
    /// <summary>Human-readable label for the InteractionScreen overlay.</summary>
    public static string DisplayName(this ScentTag tag) => tag switch
    {
        ScentTag.MawAffiliated               => "Maw-affiliated",
        ScentTag.InheritorAffiliated         => "Inheritor-affiliated",
        ScentTag.ThornCouncilAffiliated      => "Thorn Council-affiliated",
        ScentTag.CovenantEnforcerAffiliated  => "Covenant Enforcer-affiliated",
        ScentTag.HybridUndergroundAffiliated => "Hybrid Underground-affiliated",
        ScentTag.UnsheathedAffiliated        => "Unsheathed-affiliated",
        ScentTag.MerchantAffiliated          => "Merchant-affiliated",
        ScentTag.RecentlyKilled              => "Recently killed",
        ScentTag.Frightened                  => "Frightened",
        ScentTag.CarriesContraband           => "Carries contraband",
        ScentTag.Wounded                     => "Wounded",
        _                                     => "—",
    };

    /// <summary>
    /// Map a faction id to the corresponding affiliation tag. Returns
    /// <see cref="ScentTag.None"/> for empty / unknown faction ids.
    /// </summary>
    public static ScentTag FromFactionId(string factionId) => factionId?.ToLowerInvariant() switch
    {
        "maw"                  => ScentTag.MawAffiliated,
        "inheritors"           => ScentTag.InheritorAffiliated,
        "thorn_council"        => ScentTag.ThornCouncilAffiliated,
        "covenant_enforcers"   => ScentTag.CovenantEnforcerAffiliated,
        "hybrid_underground"   => ScentTag.HybridUndergroundAffiliated,
        "unsheathed"           => ScentTag.UnsheathedAffiliated,
        "merchant_guilds"      => ScentTag.MerchantAffiliated,
        _                      => ScentTag.None,
    };

    /// <summary>True if this tag carries narrative weight — e.g. faction reveals.</summary>
    public static bool IsNarrative(this ScentTag tag) =>
        tag != ScentTag.None && (byte)tag < 16;
}
