using CashLineERP.Domain.Common;
using CashLineERP.SharedKernel.Inventory;

namespace CashLineERP.Domain.Inventory;

public sealed class WarehouseTransferLine : Entity
{
    public long Id { get; private set; }

    public long WarehouseTransferId { get; private set; }

    public int LineNumber { get; private set; }

    public long ItemId { get; private set; }

    public long? FromWarehouseLocationId { get; private set; }

    public long? ToWarehouseLocationId { get; private set; }

    public decimal QuantityTransferred { get; private set; }

    public string UnitOfMeasureCode { get; private set; } = string.Empty;

    public decimal? UnitCost { get; private set; }

    public string StockStatus { get; private set; } = "AVAILABLE";

    public string? BatchNumber { get; private set; }

    public string? SerialNumber { get; private set; }

    public string? Notes { get; private set; }

    public WarehouseTransferLine(
        long warehouseTransferId,
        int lineNumber,
        long itemId,
        long? fromWarehouseLocationId,
        long? toWarehouseLocationId,
        decimal quantityTransferred,
        string unitOfMeasureCode,
        decimal? unitCost,
        string stockStatus,
        string? batchNumber,
        string? serialNumber,
        string? notes)
    {
        LotSerialTrackingGuard.EnsureSerialQuantity(serialNumber, quantityTransferred, "Warehouse transfer line");
        WarehouseTransferId = warehouseTransferId;
        LineNumber = lineNumber;
        ItemId = itemId;
        FromWarehouseLocationId = fromWarehouseLocationId;
        ToWarehouseLocationId = toWarehouseLocationId;
        QuantityTransferred = quantityTransferred;
        UnitOfMeasureCode = unitOfMeasureCode;
        UnitCost = unitCost;
        StockStatus = InventoryStockStatusPolicy.Normalize(stockStatus);
        BatchNumber = LotSerialTrackingGuard.NormalizeTrackingCode(batchNumber);
        SerialNumber = LotSerialTrackingGuard.NormalizeTrackingCode(serialNumber);
        Notes = notes;
    }

    private WarehouseTransferLine()
    {
    }
}
