using System.Text.Json;
using Tiku.Application.Commerce;

namespace Tiku.Infrastructure.Commerce;

internal sealed class ManualPaymentProvider : IPaymentProvider
{
    public string Provider => PaymentProviders.Manual;

    public Task<CreatePaymentProviderResult> CreatePaymentAsync(
        PaymentProviderAccount account,
        CreatePaymentProviderRequest request,
        CancellationToken cancellationToken = default)
    {
        var payload = JsonSerializer.SerializeToElement(new
        {
            request.OrderNo,
            request.AmountCents,
            request.Subject,
            Message = "manual_payment_requires_tenant_admin_confirmation"
        });

        return Task.FromResult(new CreatePaymentProviderResult(
            Provider,
            request.Method,
            "pending",
            null,
            payload,
            payload));
    }

    public Task<PaymentNotificationResult> ParsePaymentNotificationAsync(
        PaymentProviderAccount account,
        PaymentNotificationRequest request,
        CancellationToken cancellationToken = default)
    {
        throw new PaymentProviderException(
            "Manual payment does not accept provider notifications.",
            "manual_payment_notification_not_supported");
    }
}
