namespace ERPCore.Infra.UoW;

/// <summary>
/// Transaction boundary for stock-affecting operations (00-CORE §4). Every
/// GRN confirm, transfer dispatch/receive, adjustment, return and count post
/// runs inside a single UoW transaction so FIFO layer consumption and ledger
/// writes commit or roll back together.
/// </summary>
public interface IUnitOfWork
{
    /// <summary>Persist tracked changes without an explicit transaction scope.</summary>
    Task<int> SaveChangesAsync(CancellationToken ct = default);

    /// <summary>Run <paramref name="action"/> inside a transaction, saving and committing on success.</summary>
    Task ExecuteInTransactionAsync(Func<CancellationToken, Task> action, CancellationToken ct = default);

    /// <summary>Transactional variant that returns a value from <paramref name="action"/>.</summary>
    Task<T> ExecuteInTransactionAsync<T>(Func<CancellationToken, Task<T>> action, CancellationToken ct = default);
}
