#nullable enable
using Baya.Application.Contracts.Common;
using Microsoft.Extensions.Options;

namespace Baya.Infrastructure.CrossCutting.Seams;

/// <summary>
/// Deterministic mock <see cref="IPaymentCaptureSimulator"/> — the temporary conversion trigger until b10's
/// real card capture. It returns a <i>succeeded</i> capture with a stable fake gateway reference and the
/// configured PSP fee, so <c>ConvertRequestToBookingCommand</c> can be exercised end-to-end now. Set
/// <see cref="PaymentCaptureOptions.ForceFailure"/> to exercise the "capture failed → no booking" path.
/// The real capture replaces this registration in b10 — no mock behaviour is baked into any handler.
/// </summary>
public sealed class MockPaymentCaptureSimulator(IOptions<SeamOptions> options) : IPaymentCaptureSimulator
{
    private readonly PaymentCaptureOptions _options = options.Value.PaymentCapture;

    public ValueTask<PaymentCaptureResult> ConfirmCaptureAsync(long bookingRequestId, CancellationToken cancellationToken = default)
    {
        if (_options.ForceFailure)
            return ValueTask.FromResult(new PaymentCaptureResult(false, string.Empty, null));

        return ValueTask.FromResult(new PaymentCaptureResult(
            Succeeded: true,
            GatewayReference: $"mock-capture-{bookingRequestId}",
            PspFeeAmount: _options.PspFeeAmount));
    }
}
