using Web.Api.Common;
using MediatR;

namespace Web.Api.Endpoints.Donation;

/// <summary>후원 리모콘 상태 관리</summary>
internal sealed class RemoteState : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 일시정지/후원수신/음성만/영상만 상태 + 대기열 조회
        app.MapGet("api/donation/remote/state/{widgetToken}", async (
            string widgetToken,
            ISender sender,
            CancellationToken ct
        ) => {
            var data = await sender.Send(new Application.Features.Api.DonationRemote.GetState.Query(widgetToken), ct);

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

        /// 리모콘 상태 변경 (isPaused, isAccepting, isAudioOnly, isVideoOnly)
        app.MapPost("api/donation/remote/state", async (
            Application.Features.Api.DonationRemote.UpdateState.Command body,
            ISender sender,
            CancellationToken ct
        ) => {
            await sender.Send(body, ct);

            return ApiResponse.Ok();
        })
        .WithTags("DonationRemote")
        .RequireAuthorization();
    }
}