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

namespace Web.Api.Endpoints.Studio.Settings;

/// <summary>채널 연결 — YouTube OAuth URL 반환</summary>
internal sealed class GetYouTubeConnectUrl : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/studio/youtube-connect-url", async (
            ClaimsPrincipal user,
            string redirectUri,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var result = await sender.Send(new Application.Features.Api.Studio.GetYouTubeConnectUrl.Query(memberID, redirectUri), ct);
            return result.Match(
                data => ApiResponse.Ok(data),
                CustomResults.Problem
            );
        })
        .WithTags("Studio")
        .RequireAuthorization();
    }
}