using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// Purchase order header (FR-PROC-03..06). Mutable aggregate with a
/// <see cref="RowVersion"/> ETag token; editable while open (FR-PROC-05).
/// Phase 1 auto-approves on creation; <see cref="ApprovalRequired"/> is retained
/// for the future approval workflow. Totals are computed server-side from lines
/// (not stored). Model: docs/10 Part C.2.
/// </summary>
public class PurchaseOrder
{
    public int PoId { get; set; }
    public string DocNo { get; set; } = string.Empty;

    public int VendorId { get; set; }
    public Vendor? Vendor { get; set; }

    public int? RequisitionId { get; set; }
    public Requisition? Requisition { get; set; }

    public PurchaseOrderStatus Status { get; set; } = PurchaseOrderStatus.Draft;
    public bool ApprovalRequired { get; set; }

    public int CreatedBy { get; set; }
    public User? Creator { get; set; }

    public DateTime CreatedAt { get; set; }
    public DateTime? UpdatedAt { get; set; }

    /// <summary>PostgreSQL xmin-backed optimistic concurrency token (ETag source).</summary>
    public uint RowVersion { get; set; }

    public ICollection<PoLine> Lines { get; set; } = new List<PoLine>();
}
