using Web.Api.Common;
using Web.Api.Extensions;
using Domain.Entities.Notifications.ValueObject;
using MediatR;
using System.Security.Claims;

namespace Web.Api.Endpoints.Notification;

/// <summary>알림 목록</summary>
internal sealed class List : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        /// 알림 목록 (타입별 필터, 페이징. NotificationBell + 알림 페이지용)
        app.MapGet("api/notification/list", async (
            NotificationType? type,
            int page,
            ushort perPage,
            ClaimsPrincipal user,
            ISender sender,
            CancellationToken ct
        ) => {
            var memberID = user.GetRequiredMemberID();
            var data = await sender.Send(new Application.Features.Api.Notification.GetList.Query(memberID, type, page, perPage), ct);

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