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

namespace Web.Api.Endpoints.MyPage;

/// <summary>프로필 드롭다운 메뉴 데이터</summary>
internal sealed class Dropdown : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 프로필 썸네일/닉네임 + 후원 가능 잔액 + 출금 가능 금액 (채널 소유자만)
        app.MapGet("api/mypage/dropdown", async (
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var result = await sender.Send(new Application.Features.Api.MyPage.Dropdown.Query(memberID), ct);

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