using System.Collections.Generic;
using Baya.Application.Models.Common;
using Baya.Application.Models.Payments;
using Mediator;

namespace Baya.Application.Features.Payments.Commands.HandlePaymentWebhook;

/// <summary>
/// The verify-then-dedup-then-mutate ingest for every inbound PSP callback. It verifies the signature, upserts
/// <c>payment_webhook_events</c> <b>first</b> on <c>(provider_code, external_event_id)</c> — no-op on a
/// duplicate replay — and, on a new success event, re-verifies server-side and dispatches
/// <c>ConfirmPaymentAndPostLedger</c>, all under a Redis <c>lock(booking:{id}:payment)</c> with the DB uniques
/// as the authoritative backstop. Authenticated by signature, not a user session; at-least-once tolerant.
/// </summary>
/// <param name="Provider">The provider code from the route (<c>zarinpal</c>/<c>sadad</c>/…).</param>
/// <param name="Headers">The raw callback headers (signature material for the verifier).</param>
/// <param name="RawBody">The raw callback body — stored verbatim in <c>payload_json</c>.</param>
public record HandlePaymentWebhookCommand(string Provider, IReadOnlyDictionary<string, string> Headers, string RawBody)
    : IRequest<OperationResult<WebhookIngestResult>>;
