using System.ComponentModel.DataAnnotations.Schema; namespace Distribution.Models { public class Order : Template { public Guid? FK_SaleId { get; set; } [ForeignKey("FK_SaleId")] public Sale? Sale { get; set; } public Guid CreatedByUserId { get; set; } [ForeignKey("CreatedByUserId")] public User CreatedByUser { get; set; } /// Set once an Invoice is created for this PO (either mode). No DB-level FK /// constraint — configured explicitly in Fluent API per order_invoice_lifecycle.md. public Guid? InvoiceId { get; set; } public DateTime OrderDate { get; set; } public Guid FK_StoreId { get; set; } [ForeignKey("FK_StoreId")] public Store Store { get; set; } public decimal TotalAmount { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Pending; public DateTime? FulfilledAt { get; set; } /// Null = Shop PO (items editable). Set = Confirmed PO (items locked). Not modeled /// as an explicit field in order_invoice_lifecycle.md's diagram, but required to implement /// its Business Rule 1 (item edits gated on confirmation) independent of Invoice existing — /// Mode B confirms a PO with no Invoice at all. public DateTime? ConfirmedAt { get; set; } public Guid? ConfirmedByUserId { get; set; } [ForeignKey("ConfirmedByUserId")] public User? ConfirmedByUser { get; set; } public ICollection OrderItems { get; set; } = new List(); } }