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

namespace Web.Api.Endpoints.Donation;

/// <summary>후원 전송</summary>
internal sealed class Send : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 후원 전송 (지갑 차감 → Donation 생성 → 알림 큐 → SignalR 브로드캐스트)
        app.MapPost("api/donation/send", async (
            Application.Features.Api.Donation.Send.Command body,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var command = body with { SponsorMemberID = memberID };
            var data = await sender.Send(command, ct);
            return ApiResponse.Ok(data);
        })
        .WithTags("Donation")
        .RequireAuthorization();
    }
}