using CashLineERP.SharedKernel.Inventory;

namespace CashLineERP.Domain.Sales;

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

    public long SalesReturnId { get; private set; }

    public int LineNumber { get; private set; }

    public long DispatchOrderLineId { get; private set; }

    public long SalesOrderLineId { 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 SalesReturnLine(
        long salesReturnId,
        int lineNumber,
        long dispatchOrderLineId,
        long salesOrderLineId,
        long itemId,
        decimal quantityReturned,
        long? warehouseLocationId,
        string? batchNumber,
        string? serialNumber,
        string? notes)
    {
        LotSerialTrackingGuard.EnsureSerialQuantity(serialNumber, quantityReturned, "Sales return line");
        SalesReturnId = salesReturnId;
        LineNumber = lineNumber;
        DispatchOrderLineId = dispatchOrderLineId;
        SalesOrderLineId = salesOrderLineId;
        ItemId = itemId;
        QuantityReturned = quantityReturned;
        WarehouseLocationId = warehouseLocationId;
        BatchNumber = LotSerialTrackingGuard.NormalizeTrackingCode(batchNumber);
        SerialNumber = LotSerialTrackingGuard.NormalizeTrackingCode(serialNumber);
        Notes = notes;
    }

    private SalesReturnLine()
    {
    }
}
