using PowderCoating.Core.Enums;

namespace PowderCoating.Core.Entities;

public class PurchaseOrder : BaseEntity
{
    public string PoNumber { get; set; } = string.Empty;

    public int VendorId { get; set; }
    public virtual Vendor Vendor { get; set; } = null!;

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

    public DateTime OrderDate { get; set; } = DateTime.UtcNow;
    public DateTime? ExpectedDeliveryDate { get; set; }
    public DateTime? ReceivedDate { get; set; }

    public decimal ShippingCost { get; set; } = 0;
    public decimal SubTotal { get; set; } = 0;
    public decimal TotalAmount { get; set; } = 0;

    public string? Notes { get; set; }
    public string? InternalNotes { get; set; }

    // Optional link to a Bill created after receipt
    public int? BillId { get; set; }
    public virtual Bill? Bill { get; set; }

    public virtual ICollection<PurchaseOrderItem> Items { get; set; } = new List<PurchaseOrderItem>();
}

public class PurchaseOrderItem : BaseEntity
{
    public int PurchaseOrderId { get; set; }
    public virtual PurchaseOrder PurchaseOrder { get; set; } = null!;

    // Null for custom/non-inventory line items
    public int? InventoryItemId { get; set; }
    public virtual InventoryItem? InventoryItem { get; set; }

    // Used when InventoryItemId is null
    public string? Description { get; set; }
    public string? UnitOfMeasure { get; set; }

    public decimal QuantityOrdered { get; set; }
    public decimal QuantityReceived { get; set; } = 0;
    public decimal UnitCost { get; set; }
    public decimal LineTotal { get; set; }

    public string? Notes { get; set; }
}
