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

namespace Web.Api.Endpoints.Studio.Settlement;

/// <summary>정산 — 계좌 삭제</summary>
internal sealed class DeleteAccount : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapDelete("api/studio/settlement/account/{id:int}", async (
            int id,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var result = await sender.Send(new Application.Features.Api.Studio.Settlement.DeleteAccount.Command(memberID, id), ct);

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