namespace Theriapolis.Core.Persistence;

/// <summary>
/// Phase 6 M2 — serializable snapshot of <see cref="Rules.Reputation.PlayerReputation"/>.
/// Plain-data fields only; rebuilt back into the live aggregate by the
/// PlayScreen restore path.
///
/// Round-trips via <c>SaveCodec</c> tags 110 (faction standings) and 112
/// (reputation aggregate). The split lets the codec emit faction
/// standings even when no personal records exist, keeping save files
/// small for short playthroughs.
/// </summary>
public sealed class ReputationSnapshot
{
    /// <summary>Faction id → integer standing in <c>±C.REP_MAX</c>.</summary>
    public Dictionary<string, int> FactionStandings { get; set; } = new();

    /// <summary>Per-NPC personal records, keyed by role tag.</summary>
    public List<PersonalDispositionSnapshot> Personal { get; set; } = new();

    /// <summary>Most recent <see cref="Rules.Reputation.RepLedger.MaxEntries"/> events.</summary>
    public List<RepEventSnapshot> Ledger { get; set; } = new();
}

public sealed class PersonalDispositionSnapshot
{
    public string RoleTag                 { get; set; } = "";
    public int    Score                   { get; set; }
    public byte   Trust                   { get; set; }      // TrustLevel byte value
    public bool   Betrayed                { get; set; }
    public long   LastInteractionSeconds  { get; set; }
    public string[] MemoryTags            { get; set; } = System.Array.Empty<string>();
    public RepEventSnapshot[] Log         { get; set; } = System.Array.Empty<RepEventSnapshot>();
}

public sealed class RepEventSnapshot
{
    public int    SequenceId       { get; set; }   // Phase 6 M5
    public byte   Kind             { get; set; }   // RepEventKind byte value
    public string FactionId        { get; set; } = "";
    public string RoleTag          { get; set; } = "";
    public int    Magnitude        { get; set; }
    public string Note             { get; set; } = "";
    public int    OriginTileX      { get; set; }
    public int    OriginTileY      { get; set; }
    public long   TimestampSeconds { get; set; }
}
