using Web.Api.Common;
using MediatR;

namespace Web.Api.Endpoints.Studio.Donation;

/// <summary>후원 알림 위젯 설정 (스튜디오 전용)</summary>
internal sealed class DonationAlertConfig : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 금액별 효과음, 이미지, 노출 시간 등 조회
        app.MapGet("api/studio/donation/alert/config/{channelID}", async (
            int channelID,
            ISender sender,
            CancellationToken ct
        ) => {
            var data = await sender.Send(new Application.Features.Api.DonationAlert.GetConfig.Query(channelID), ct);
            return ApiResponse.Ok(data);
        })
        .WithTags("StudioDonationAlert")
        .RequireAuthorization();

        /// 알림 설정 저장/수정
        app.MapPost("api/studio/donation/alert/config", async (
            Application.Features.Api.DonationAlert.SaveConfig.Command body,
            ISender sender,
            CancellationToken ct
        ) => {
            await sender.Send(body, ct);
            return ApiResponse.Ok();
        })
        .WithTags("StudioDonationAlert")
        .RequireAuthorization();

        /// 알림 설정 일괄 저장/삭제
        app.MapPost("api/studio/donation/alert/config/batch", async (
            Application.Features.Api.DonationAlert.BatchSaveConfig.Command body,
            ISender sender,
            CancellationToken ct
        ) => {
            await sender.Send(body, ct);
            return ApiResponse.Ok();
        })
        .WithTags("StudioDonationAlert")
        .RequireAuthorization();

        /// 알림 설정 삭제
        app.MapDelete("api/studio/donation/alert/config/{id}/{channelID}", async (
            int id,
            int channelID,
            ISender sender,
            CancellationToken ct
        ) => {
            await sender.Send(new Application.Features.Api.DonationAlert.DeleteConfig.Command(id, channelID), ct);
            return ApiResponse.Ok();
        })
        .WithTags("StudioDonationAlert")
        .RequireAuthorization();
    }
}