using foodmarket.Domain.Catalog;
using foodmarket.Domain.Common;

namespace foodmarket.Domain.Inventory;

// Materialized current-stock aggregate per (Product, Store). Kept in sync with StockMovement
// inserts by IStockService — never write to this entity directly.
public class Stock : TenantEntity
{
    public Guid ProductId { get; set; }
    public Product Product { get; set; } = null!;

    public Guid StoreId { get; set; }
    public Store Store { get; set; } = null!;

    public decimal Quantity { get; set; }
    public decimal ReservedQuantity { get; set; }

    /// <summary>Available = on-hand − reserved. Cannot be negative in normal flow; a negative
    /// value indicates the business allowed overselling (e.g., retail sale before physical receipt).</summary>
    public decimal Available => Quantity - ReservedQuantity;
}
