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

namespace Web.Api.Endpoints.Notification;

/// <summary>알림 읽음 처리</summary>
internal sealed class MarkRead : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 개별(notificationID) 또는 전체 읽음 처리. 뱃지 카운트 갱신.
        app.MapPost("api/notification/read", async (
            Application.Features.Api.Notification.MarkRead.Command body,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var command = body with { MemberID = memberID };
            await sender.Send(command, ct);

            return ApiResponse.Ok();
        })
        .WithTags("Notification")
        .RequireAuthorization();
    }
}