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

namespace Baya.Infrastructure.CrossCutting.Seams;

/// <summary>
/// Deterministic mock <see cref="ISettlementSplitProvider"/> — records the split intent and reports it
/// settled without moving a Rial (the platform never custodies funds). It accepts any legs whose sum is
/// positive and returns <see cref="SettlementStatus.Settled"/>. A real تسهیم adapter (each beneficiary's
/// registered SHEBA, split-by-ratio config, the ~100,000 IRR min-amount caveat; the provider credits IBANs
/// directly) replaces this registration only.
/// </summary>
public sealed class MockSettlementSplitProvider : ISettlementSplitProvider
{
    public ValueTask<SettlementResult> RegisterSplitAsync(long bookingId, IReadOnlyList<SettlementLeg> legs, CancellationToken cancellationToken = default)
    {
        var status = legs.Count > 0 && legs.Sum(l => l.AmountIrr) > 0
            ? SettlementStatus.Settled
            : SettlementStatus.Failed;
        return ValueTask.FromResult(new SettlementResult(status));
    }

    public ValueTask<SettlementResult> GetSplitStatusAsync(long bookingId, CancellationToken cancellationToken = default)
        => ValueTask.FromResult(new SettlementResult(SettlementStatus.Settled));
}
