using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// Immutable history of everything that happened to a run (docs/30 Part C). Written by
/// every mutating action and never updated or deleted, so a run's story — including the
/// figures discarded by each rework — survives in full.
/// <para><b>Addition to docs/30 Part C (recorded):</b> <see cref="RunId"/>. The doc hangs
/// events off the stage only, which leaves run-level events (cancel, terminal reject)
/// with no home and forces the detail timeline to join through stages. Keeping both
/// links makes <see cref="RunStageId"/> optional and the timeline a single query.</para>
/// </summary>
public class RunStageEvent
{
    public int EventId { get; set; }

    public int RunId { get; set; }
    public ProductionRun? Run { get; set; }

    /// <summary>Null for run-level events (Cancel).</summary>
    public int? RunStageId { get; set; }
    public RunStage? RunStage { get; set; }

    public RunStageEventType EventType { get; set; }

    public string? Note { get; set; }

    /// <summary>
    /// Event-specific detail as jsonb — consumed layers on a Start, pulled-back
    /// quantities on a RejectIntake, the full pre-rework snapshot on a TerminalReject.
    /// Pre-serialized string, written only through <c>ProductionJson</c>.
    /// </summary>
    public string? Payload { get; set; }

    public int UserId { get; set; }
    public User? User { get; set; }

    public DateTime CreatedAt { get; set; }
}
