using Web.Api.Common;
using Web.Api.Extensions;
using MediatR;
using System.Security.Claims;

namespace Web.Api.Endpoints.Payment;

/// <summary>결제 승인</summary>
internal sealed class Confirm : IEndpoint
{
    public sealed record Request(string OrderID, string TransactionID, string Method);

    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 다날 결제 완료 후 승인 API 호출 → 지갑 포인트 충전
        app.MapPost("api/payment/confirm", async (
            Request body,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var command = new Application.Features.Api.Payment.Confirm.Command(
                body.OrderID,
                body.TransactionID,
                body.Method,
                memberID
            );
            var data = await sender.Send(command, ct);

            return ApiResponse.Ok(data);
        })
        .WithTags("Payment")
        .RequireAuthorization();
    }
}