using foodmarket.Domain.Inventory;

namespace foodmarket.Application.Inventory;

public record StockMovementDraft(
    Guid ProductId,
    Guid StoreId,
    decimal Quantity,
    MovementType Type,
    string DocumentType,
    Guid? DocumentId = null,
    string? DocumentNumber = null,
    decimal? UnitCost = null,
    DateTime? OccurredAt = null,
    Guid? CreatedByUserId = null,
    string? Notes = null);

public interface IStockService
{
    /// <summary>Writes the movement + updates the materialized Stock row in a single unit of work.
    /// Returns the new on-hand quantity. Callers must commit the DbContext themselves (we don't
    /// wrap in a transaction — typical flow is as part of a document posting that already bundles
    /// multiple movements into one SaveChanges).</summary>
    Task<decimal> ApplyMovementAsync(StockMovementDraft draft, CancellationToken ct = default);

    Task<decimal> ApplyMovementsAsync(IEnumerable<StockMovementDraft> drafts, CancellationToken ct = default);
}
