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

namespace Web.Api.Endpoints.Studio.Wallet;

/// <summary>지갑 — 수익 내역</summary>
internal sealed class Revenue : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/studio/wallet/revenue", async (
            string? period,
            int page,
            int perPage,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var result = await sender.Send(new Application.Features.Api.Studio.Wallet.GetRevenue.Query(memberID, period, page < 1 ? 1 : page, perPage < 1 ? 20 : perPage), ct);

            return result.Match(
                data => ApiResponse.Ok(data),
                CustomResults.Problem
            );
        })
        .WithTags("StudioWallet")
        .RequireAuthorization();
    }
}