using Web.Api.Common;
using MediatR;

namespace Web.Api.Endpoints.Studio.Crew;

/// <summary>크루원 추가 (회원 검색으로)</summary>
internal sealed class CrewMemberAdd : IEndpoint
{
    internal sealed record AddRequest(
        int CrewID,
        int TargetMemberID,
        string Nickname,
        string? Role,
        int SortOrder = 0
    );

    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapPost("api/studio/crew/member/add", async (
            AddRequest body,
            ISender sender,
            CancellationToken ct
        ) => {
            var command = new Application.Features.Api.Crew.AddMember.Command(
                body.CrewID, body.TargetMemberID, body.Nickname, body.Role, body.SortOrder
            );
            var data = await sender.Send(command, ct);
            return ApiResponse.Ok(data);
        })
        .WithTags("StudioCrew")
        .RequireAuthorization();
    }
}