namespace ERPCore.Domain.Entities;

/// <summary>
/// One box on the template canvas (FR-MFG-03): a named step with a role label, an
/// estimated duration, a formula (<see cref="Inputs"/> + <see cref="Outputs"/>) and
/// custom field definitions. Model: docs/30 Part C.
/// </summary>
public class TemplateStage
{
    public int StageId { get; set; }

    public int TemplateId { get; set; }
    public ProductionTemplate? Template { get; set; }

    public string Name { get; set; } = string.Empty;

    /// <summary>Free text (e.g. "QA"). Informational only this phase — never enforced (FR-X-01).</summary>
    public string? RoleLabel { get; set; }

    public int EstimatedMinutes { get; set; }

    /// <summary>Canvas coordinates — stored verbatim, never interpreted server-side (FR-MFG-03).</summary>
    public decimal PosX { get; set; }
    public decimal PosY { get; set; }

    /// <summary>
    /// Custom field definitions as jsonb: <c>[{ key, label, type, options?, required }]</c>
    /// (FR-MFG-07). Held as a pre-serialized string, matching the <c>AuditLog.ChangeSet</c>
    /// precedent; always written through <c>ProductionJson</c> so the column can only ever
    /// hold canonical JSON.
    /// </summary>
    public string FieldDefs { get; set; } = "[]";

    public ICollection<StageInput> Inputs { get; set; } = new List<StageInput>();
    public ICollection<StageOutput> Outputs { get; set; } = new List<StageOutput>();
}
