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

namespace Web.Api.Endpoints.Donation;

/// <summary>후원 내역</summary>
internal sealed class History : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 후원 내역 조회 (type: "sent"=보낸 / "received"=받은, 페이징)
        app.MapGet("api/donation/history", async (
            string type,
            int page,
            ushort perPage,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var data = await sender.Send(new Application.Features.Api.Donation.History.Query(memberID, type, page, perPage), ct);

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