using CashLineERP.SharedKernel.Inventory;

namespace CashLineERP.Domain.Procurement;

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

    public long PurchaseReturnId { get; private set; }

    public int LineNumber { get; private set; }

    public long GoodsReceiptLineId { get; private set; }

    public long PurchaseOrderLineId { get; private set; }

    public long ItemId { get; private set; }

    public decimal QuantityReturned { get; private set; }

    public long? WarehouseLocationId { get; private set; }

    public string? BatchNumber { get; private set; }

    public string? SerialNumber { get; private set; }

    public string? Notes { get; private set; }

    public PurchaseReturnLine(
        long purchaseReturnId,
        int lineNumber,
        long goodsReceiptLineId,
        long purchaseOrderLineId,
        long itemId,
        decimal quantityReturned,
        long? warehouseLocationId,
        string? batchNumber,
        string? serialNumber,
        string? notes)
    {
        LotSerialTrackingGuard.EnsureSerialQuantity(serialNumber, quantityReturned, "Purchase return line");
        PurchaseReturnId = purchaseReturnId;
        LineNumber = lineNumber;
        GoodsReceiptLineId = goodsReceiptLineId;
        PurchaseOrderLineId = purchaseOrderLineId;
        ItemId = itemId;
        QuantityReturned = quantityReturned;
        WarehouseLocationId = warehouseLocationId;
        BatchNumber = LotSerialTrackingGuard.NormalizeTrackingCode(batchNumber);
        SerialNumber = LotSerialTrackingGuard.NormalizeTrackingCode(serialNumber);
        Notes = notes;
    }

    private PurchaseReturnLine()
    {
    }
}
