using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// One line of a stage's input formula (FR-MFG-04). Exactly one of the two source
/// shapes applies, enforced by <c>ProductionGraphValidator</c>:
/// <list type="bullet">
/// <item><see cref="StageInputSource.Stock"/> — <see cref="ItemId"/> set,
/// <see cref="FromOutputId"/> null. FIFO-consumed from the run warehouse at stage
/// start. Allowed on <i>any</i> stage, e.g. packaging added late.</item>
/// <item><see cref="StageInputSource.Upstream"/> — <see cref="FromOutputId"/> set to
/// an output of a <b>direct parent</b> stage, <see cref="ItemId"/> null. Flows as
/// internal WIP and never touches stock or the ledger.</item>
/// </list>
/// Model: docs/30 Part C.
/// </summary>
public class StageInput
{
    public int InputId { get; set; }

    public int StageId { get; set; }
    public TemplateStage? Stage { get; set; }

    public StageInputSource Source { get; set; }

    /// <summary>Required when <see cref="Source"/> is Stock; null when Upstream.</summary>
    public int? ItemId { get; set; }
    public Item? Item { get; set; }

    /// <summary>Required when <see cref="Source"/> is Upstream; must belong to a direct parent.</summary>
    public int? FromOutputId { get; set; }
    public StageOutput? FromOutput { get; set; }

    /// <summary>
    /// What <see cref="QtyPerBatch"/> is expressed in. Stock inputs may use
    /// <see cref="StageQtyUnit.Content"/> (ml/g) when the item has a content size; Upstream
    /// inputs are always <see cref="StageQtyUnit.Pack"/> — WIP is counted in the unit its
    /// source output declares.
    /// </summary>
    public StageQtyUnit QtyUnit { get; set; } = StageQtyUnit.Pack;

    public decimal QtyPerBatch { get; set; }
}
