using CashLineERP.SharedKernel.Inventory;

namespace CashLineERP.Domain.Procurement;

public sealed class GoodsReceiptLine
{
    public long Id { get; private set; }

    public long GoodsReceiptId { get; private set; }

    public int LineNumber { get; private set; }

    public long PurchaseOrderLineId { get; private set; }

    public long ItemId { get; private set; }

    public long WarehouseId { get; private set; }

    public long? WarehouseLocationId { get; private set; }

    public decimal QuantityReceived { get; private set; }

    public decimal QuantityAccepted { get; private set; }

    public decimal QuantityRejected { get; private set; }

    public string? BatchNumber { get; private set; }

    public string? SerialNumber { get; private set; }

    public GoodsReceiptLine(
        long goodsReceiptId,
        int lineNumber,
        long purchaseOrderLineId,
        long itemId,
        long warehouseId,
        long? warehouseLocationId,
        decimal quantityReceived,
        decimal quantityAccepted,
        decimal quantityRejected,
        string? batchNumber,
        string? serialNumber)
    {
        LotSerialTrackingGuard.EnsureSerialQuantity(serialNumber, quantityReceived, "Goods receipt line");
        GoodsReceiptId = goodsReceiptId;
        LineNumber = lineNumber;
        PurchaseOrderLineId = purchaseOrderLineId;
        ItemId = itemId;
        WarehouseId = warehouseId;
        WarehouseLocationId = warehouseLocationId;
        QuantityReceived = quantityReceived;
        QuantityAccepted = quantityAccepted;
        QuantityRejected = quantityRejected;
        BatchNumber = LotSerialTrackingGuard.NormalizeTrackingCode(batchNumber);
        SerialNumber = LotSerialTrackingGuard.NormalizeTrackingCode(serialNumber);
    }

    private GoodsReceiptLine()
    {
    }
}
