#nullable enable
namespace Baya.Application.Contracts.Payments;

/// <summary>
/// A distributed mutex around a money-path critical section (real impl: StackExchange.Redis with a lease/
/// expiry, key convention <c>booking:{id}:payment</c>). It is the <b>fast first line</b> so a double callback
/// and a user retry don't both start a money mutation — but <b>never the sole correctness guarantee</b>: if
/// Redis is down or the lease expires, the DB uniques/state-machine remain the authoritative backstop.
/// </summary>
public interface IDistributedLock
{
    /// <summary>Acquires the lock for <paramref name="key"/>; dispose the handle to release. The mock is an
    /// in-process semaphore per key, so the money-path code runs the same shape it will with real Redis.</summary>
    ValueTask<IAsyncDisposable> AcquireAsync(string key, CancellationToken cancellationToken = default);
}
