namespace Apollinare.Domain.Entities.Warehouse;

/// <summary>
/// Partita/Lotto di un articolo
/// </summary>
public class ArticleBatch : BaseEntity
{
    /// <summary>
    /// Articolo di riferimento
    /// </summary>
    public int ArticleId { get; set; }

    /// <summary>
    /// Codice partita/lotto
    /// </summary>
    public string BatchNumber { get; set; } = string.Empty;

    /// <summary>
    /// Data di produzione
    /// </summary>
    public DateTime? ProductionDate { get; set; }

    /// <summary>
    /// Data di scadenza
    /// </summary>
    public DateTime? ExpiryDate { get; set; }

    /// <summary>
    /// Lotto fornitore
    /// </summary>
    public string? SupplierBatch { get; set; }

    /// <summary>
    /// ID fornitore di origine
    /// </summary>
    public int? SupplierId { get; set; }

    /// <summary>
    /// Costo specifico della partita
    /// </summary>
    public decimal? UnitCost { get; set; }

    /// <summary>
    /// Quantità iniziale del lotto
    /// </summary>
    public decimal InitialQuantity { get; set; }

    /// <summary>
    /// Quantità corrente disponibile
    /// </summary>
    public decimal CurrentQuantity { get; set; }

    /// <summary>
    /// Quantità riservata
    /// </summary>
    public decimal ReservedQuantity { get; set; }

    /// <summary>
    /// Stato della partita
    /// </summary>
    public BatchStatus Status { get; set; } = BatchStatus.Available;

    /// <summary>
    /// Risultato controllo qualità
    /// </summary>
    public QualityStatus? QualityStatus { get; set; }

    /// <summary>
    /// Data ultimo controllo qualità
    /// </summary>
    public DateTime? LastQualityCheckDate { get; set; }

    /// <summary>
    /// Certificazioni associate (JSON array)
    /// </summary>
    public string? Certifications { get; set; }

    /// <summary>
    /// Note sulla partita
    /// </summary>
    public string? Notes { get; set; }

    // Navigation properties
    public WarehouseArticle? Article { get; set; }
    public ICollection<StockLevel> StockLevels { get; set; } = new List<StockLevel>();
    public ICollection<StockMovementLine> MovementLines { get; set; } = new List<StockMovementLine>();
    public ICollection<ArticleSerial> Serials { get; set; } = new List<ArticleSerial>();
}

/// <summary>
/// Stato della partita/lotto
/// </summary>
public enum BatchStatus
{
    /// <summary>
    /// Disponibile per utilizzo
    /// </summary>
    Available = 0,

    /// <summary>
    /// In quarantena (in attesa controllo qualità)
    /// </summary>
    Quarantine = 1,

    /// <summary>
    /// Bloccato (non utilizzabile)
    /// </summary>
    Blocked = 2,

    /// <summary>
    /// Scaduto
    /// </summary>
    Expired = 3,

    /// <summary>
    /// Esaurito
    /// </summary>
    Depleted = 4
}

/// <summary>
/// Stato qualità della partita
/// </summary>
public enum QualityStatus
{
    /// <summary>
    /// Non controllato
    /// </summary>
    NotChecked = 0,

    /// <summary>
    /// Approvato
    /// </summary>
    Approved = 1,

    /// <summary>
    /// Respinto
    /// </summary>
    Rejected = 2,

    /// <summary>
    /// Approvato con riserva
    /// </summary>
    ConditionallyApproved = 3
}
