using Web.Api.Common;
using MediatR;
using Domain.Entities.Donations.ValueObject;

namespace Web.Api.Endpoints.Widget;

/// <summary>후원 순위 (OBS 위젯용, 인증 불필요)</summary>
internal sealed class DonationRanking : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/widget/rank/{channelID}", async (
            int channelID,
            RankPeriodType? periodType,
            int? maxRank,
            ISender sender,
            CancellationToken ct
        ) => {
            var data = await sender.Send(new Application.Features.Api.DonationRank.GetRanking.Query(
                channelID,
                periodType ?? RankPeriodType.Daily,
                maxRank ?? 5
            ), ct);
            return ApiResponse.Ok(data);
        })
        .WithTags("Widget")
        .AllowAnonymous();
    }
}