namespace Apollinare.Domain.Entities.Warehouse;

/// <summary>
/// Giacenza articolo per magazzino, partita
/// </summary>
public class StockLevel : BaseEntity
{
    /// <summary>
    /// Articolo
    /// </summary>
    public int ArticleId { get; set; }

    /// <summary>
    /// Magazzino
    /// </summary>
    public int WarehouseId { get; set; }

    /// <summary>
    /// Partita (opzionale, se gestito a lotti)
    /// </summary>
    public int? BatchId { get; set; }

    /// <summary>
    /// Quantità fisica in giacenza
    /// </summary>
    public decimal Quantity { get; set; }

    /// <summary>
    /// Quantità riservata (impegnata per ordini)
    /// </summary>
    public decimal ReservedQuantity { get; set; }

    /// <summary>
    /// Quantità disponibile = Quantity - ReservedQuantity
    /// </summary>
    public decimal AvailableQuantity => Quantity - ReservedQuantity;

    /// <summary>
    /// Quantità in ordine (in arrivo)
    /// </summary>
    public decimal OnOrderQuantity { get; set; }

    /// <summary>
    /// Valore totale della giacenza (calcolato)
    /// </summary>
    public decimal? StockValue { get; set; }

    /// <summary>
    /// Costo unitario medio per questa giacenza
    /// </summary>
    public decimal? UnitCost { get; set; }

    /// <summary>
    /// Data ultimo movimento
    /// </summary>
    public DateTime? LastMovementDate { get; set; }

    /// <summary>
    /// Data ultimo inventario
    /// </summary>
    public DateTime? LastInventoryDate { get; set; }

    /// <summary>
    /// Ubicazione specifica nel magazzino (scaffale, corridoio, etc.)
    /// </summary>
    public string? LocationCode { get; set; }

    // Navigation properties
    public WarehouseArticle? Article { get; set; }
    public WarehouseLocation? Warehouse { get; set; }
    public ArticleBatch? Batch { get; set; }
}
