using Baya.Application.Contracts.Common;

namespace Baya.Infrastructure.CrossCutting.Seams;

/// <summary>
/// Development-only <see cref="ISmsSender"/> decorator: forwards to the real (mock) sender so the code is
/// still logged, and additionally captures it in <see cref="DevOtpStore"/> so the Development-only
/// <c>/api/v1/dev/last_otp/{phone}</c> endpoint can serve it to a browser / e2e test. Registered ONLY in the
/// Development environment (see <c>DevelopmentSeamExtensions.AddDevelopmentOtpCapture</c>); it changes no
/// auth behaviour — the OTP is generated, validated and rate-limited exactly as before.
/// </summary>
public sealed class DevCapturingSmsSender(ISmsSender inner, DevOtpStore store) : ISmsSender
{
    public Task SendOtpAsync(string phone, string code, CancellationToken cancellationToken = default)
    {
        store.Capture(phone, code);
        return inner.SendOtpAsync(phone, code, cancellationToken);
    }

    public Task SendAsync(string phone, string message, CancellationToken cancellationToken = default)
        => inner.SendAsync(phone, message, cancellationToken);
}
