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

namespace Baya.Infrastructure.CrossCutting.Seams;

/// <summary>
/// Default <see cref="ILicenseVerificationService"/> — and the mock. The MoH establishment-permit registry and
/// eNamad have <b>no public B2B API</b>, so at MVP licensing is a manual admin approval: every call returns
/// <see cref="LicenseVerificationStatus.NeedsManualReview"/>, and <c>VerifyPartnerCenter</c> records the human
/// decision. Set <see cref="LicenseVerificationOptions.AutoApprove"/> to have the mock return
/// <see cref="LicenseVerificationStatus.Valid"/> (test the auto-approve path). When a real registry/API becomes
/// available, a real implementation replaces this registration and starts returning real verdicts — callers are
/// unchanged.
/// </summary>
public sealed class MockLicenseVerificationService(IOptions<SeamOptions> options) : ILicenseVerificationService
{
    private LicenseVerificationOptions Options => options.Value.LicenseVerification;

    public Task<LicenseVerdict> VerifyEstablishmentPermitAsync(string permitNo, CancellationToken cancellationToken = default)
        => Task.FromResult(Verdict($"establishment permit '{permitNo}'"));

    public Task<LicenseVerdict> VerifyENamadAsync(string enamadCode, CancellationToken cancellationToken = default)
        => Task.FromResult(Verdict($"eNamad '{enamadCode}'"));

    private LicenseVerdict Verdict(string subject)
        => Options.AutoApprove
            ? new LicenseVerdict(LicenseVerificationStatus.Valid, $"Auto-approved (mock) for {subject}.")
            : new LicenseVerdict(LicenseVerificationStatus.NeedsManualReview,
                $"No automated registry for {subject}; requires a manual admin decision.");
}
