using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// Goods Receipt Note header (FR-GRN-01/02). Raised against a PO or direct
/// (<see cref="PoId"/> null). On confirm each line creates a FIFO layer and posts
/// an inbound ledger entry. Mutable aggregate with an <see cref="RowVersion"/>
/// concurrency token (docs/10 C.10). Model: docs/10 Part C.3.
/// </summary>
public class Grn
{
    public int GrnId { get; set; }
    public string DocNo { get; set; } = string.Empty;

    public int? PoId { get; set; }
    public PurchaseOrder? PurchaseOrder { get; set; }

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

    public int WarehouseId { get; set; }
    public Warehouse? Warehouse { get; set; }

    public GrnStatus Status { get; set; } = GrnStatus.Draft;

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

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

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

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