namespace Apollinare.Domain.Entities.Warehouse;

/// <summary>
/// Seriale/Matricola di un articolo
/// </summary>
public class ArticleSerial : BaseEntity
{
    /// <summary>
    /// Articolo di riferimento
    /// </summary>
    public int ArticleId { get; set; }

    /// <summary>
    /// Partita di appartenenza (opzionale)
    /// </summary>
    public int? BatchId { get; set; }

    /// <summary>
    /// Numero seriale/matricola
    /// </summary>
    public string SerialNumber { get; set; } = string.Empty;

    /// <summary>
    /// Seriale del produttore (se diverso)
    /// </summary>
    public string? ManufacturerSerial { get; set; }

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

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

    /// <summary>
    /// Magazzino corrente
    /// </summary>
    public int? CurrentWarehouseId { get; set; }

    /// <summary>
    /// Stato del seriale
    /// </summary>
    public SerialStatus Status { get; set; } = SerialStatus.Available;

    /// <summary>
    /// Costo specifico del seriale
    /// </summary>
    public decimal? UnitCost { get; set; }

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

    /// <summary>
    /// ID cliente (se venduto)
    /// </summary>
    public int? CustomerId { get; set; }

    /// <summary>
    /// Data di vendita
    /// </summary>
    public DateTime? SoldDate { get; set; }

    /// <summary>
    /// Riferimento documento di vendita
    /// </summary>
    public string? SalesReference { get; set; }

    /// <summary>
    /// Attributi aggiuntivi (JSON)
    /// </summary>
    public string? Attributes { get; set; }

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

    // Navigation properties
    public WarehouseArticle? Article { get; set; }
    public ArticleBatch? Batch { get; set; }
    public WarehouseLocation? CurrentWarehouse { get; set; }
    public ICollection<StockMovementLine> MovementLines { get; set; } = new List<StockMovementLine>();
}

/// <summary>
/// Stato del seriale
/// </summary>
public enum SerialStatus
{
    /// <summary>
    /// Disponibile in magazzino
    /// </summary>
    Available = 0,

    /// <summary>
    /// Riservato (impegnato per ordine)
    /// </summary>
    Reserved = 1,

    /// <summary>
    /// Venduto
    /// </summary>
    Sold = 2,

    /// <summary>
    /// In riparazione
    /// </summary>
    InRepair = 3,

    /// <summary>
    /// Difettoso/Danneggiato
    /// </summary>
    Defective = 4,

    /// <summary>
    /// Restituito
    /// </summary>
    Returned = 5,

    /// <summary>
    /// Dismesso
    /// </summary>
    Disposed = 6
}
