using Web.Api.Common;
using MediatR;

namespace Web.Api.Endpoints.Studio.Crew;

/// <summary>크루원 정보 수정</summary>
internal sealed class CrewMemberUpdate : IEndpoint
{
    internal sealed record UpdateRequest(
        int CrewMemberID,
        string Nickname,
        string? Role,
        int SortOrder,
        bool IsActive
    );

    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapPut("api/studio/crew/member/{crewMemberID}", async (
            int crewMemberID,
            UpdateRequest body,
            ISender sender,
            CancellationToken ct
        ) => {
            var command = new Application.Features.Api.Crew.UpdateMember.Command(
                crewMemberID, body.Nickname, body.Role, body.SortOrder, body.IsActive
            );
            await sender.Send(command, ct);
            return ApiResponse.Ok();
        })
        .WithTags("StudioCrew")
        .RequireAuthorization();
    }
}