namespace Theriapolis.Core.Rules.Reputation;

/// <summary>
/// Phase 6 M2 — typed, append-only log entry recording a single reputation
/// change. Events are the *cause*; the resulting standing/disposition
/// update is the *effect*. We keep the cause around so the UI can answer
/// "why does so-and-so hate me?" with breadcrumbs.
///
/// Phase 6 M5 layers propagation on top: events written here can fan out
/// to other settlements with distance/time decay.
/// </summary>
public enum RepEventKind : byte
{
    Dialogue   = 0,
    Quest      = 1,
    Combat     = 2,
    Rescue     = 3,
    Betrayal   = 4,
    Gift       = 5,
    Trade      = 6,
    Scent      = 7,
    Death      = 8,    // killing a faction-affiliated NPC
    Aid        = 9,    // healing / curing / saving a non-combatant
    Crime      = 10,
    /// <summary>
    /// Phase 6.5 M5 — an NPC's scent-detection roll exposed the player
    /// as a hybrid. Per-NPC personal-only event (no faction propagation
    /// in M5; Phase 8's scent simulation can extend this).
    /// </summary>
    HybridDetected = 11,
    Misc       = 255,
}

/// <summary>One immutable reputation event. Time-stamped and tagged with
/// origin coordinates so propagation can apply distance/time decay.</summary>
public sealed record RepEvent
{
    /// <summary>
    /// Phase 6 M5 — monotonically increasing id assigned by
    /// <see cref="RepLedger.Append"/>. Used as the deterministic-RNG
    /// seed for frontier-settlement delivery coin-flips. 0 means "not
    /// yet appended to a ledger".
    /// </summary>
    public int SequenceId { get; init; } = 0;

    public RepEventKind Kind { get; init; } = RepEventKind.Misc;

    /// <summary>Faction id this event affects (empty = personal-only event).</summary>
    public string FactionId { get; init; } = "";

    /// <summary>NPC role tag this event affects personally (empty = world-only event).</summary>
    public string RoleTag { get; init; } = "";

    /// <summary>Magnitude before opposition matrix / decay. Sign indicates direction.</summary>
    public int Magnitude { get; init; }

    /// <summary>Free-form origin context: "saved-her-kit-from-drowning" / "killed-thornfield-guard".</summary>
    public string Note { get; init; } = "";

    /// <summary>World-tile coordinates where the event occurred (for M5 propagation).</summary>
    public int OriginTileX { get; init; }
    public int OriginTileY { get; init; }

    /// <summary>WorldClock seconds at the time the event was logged.</summary>
    public long TimestampSeconds { get; init; }
}
