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

namespace Web.Api.Endpoints.Note;

/// <summary>쪽지 전송</summary>
internal sealed class Send : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 쪽지 발송 (AppHub ReceiveNote 실시간 알림. 시스템 쪽지도 이 경로 사용)
        app.MapPost("api/note/send", async (
            Application.Features.Api.Note.SendNote.Command body,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var command = body with { SenderMemberID = memberID };
            var data = await sender.Send(command, ct);

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