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

namespace Web.Api.Endpoints.Note;

/// <summary>받은 쪽지함</summary>
internal sealed class Inbox : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 받은 쪽지함 (읽음/안읽음 필터, 페이징, unreadCount 포함)
        app.MapGet("api/note/inbox", async (
            bool? isRead,
            int page,
            ushort perPage,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var data = await sender.Send(new Application.Features.Api.Note.GetInbox.Query(memberID, isRead, page, perPage), ct);

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