using ERPCore.Domain.Entities;

namespace ERPCore.Services.Interfaces;

/// <summary>A signed base-UOM change to an item's stock at one warehouse.</summary>
public sealed record StockDelta(int ItemId, int? BinId, int? BatchId, decimal QtyDelta);

/// <summary>
/// Shared poster for stock-affecting documents (adjustments, count variances,
/// purchase returns). Applies signed deltas — negative consumes FIFO layers
/// oldest-first (row-locked, negative-stock blocked), positive creates a layer at
/// last cost — and appends the ledger entries. Runs inside the caller's UoW
/// transaction (the caller owns numbering, the header, and the commit); the
/// document must already be saved so its id is a valid ledger <c>sourceDocId</c>.
/// </summary>
public interface IStockMutator
{
    Task<IReadOnlyList<StockLedger>> ApplyAsync(
        int warehouseId, string sourceDocType, int sourceDocId, DateTime now,
        IReadOnlyList<StockDelta> deltas, CancellationToken ct = default);
}
