using Baya.Application.Common;
using Baya.Application.Contracts.SupportAlerts;
using Baya.Application.Models.Common;
using Baya.Application.Models.SupportAlerts;
using Mediator;

namespace Baya.Application.Features.SupportAlerts.Queries.ListSupportAlerts;

internal sealed class ListSupportAlertsQueryHandler(ISupportAlertService supportAlerts)
    : IRequestHandler<ListSupportAlertsQuery, OperationResult<PagedResult<SupportAlertDto>>>
{
    public async ValueTask<OperationResult<PagedResult<SupportAlertDto>>> Handle(ListSupportAlertsQuery request, CancellationToken cancellationToken)
    {
        var (page, pageSize) = Pagination.Normalize(request.Page, request.PageSize);
        var result = await supportAlerts.ListAsync(request.Type, request.Status, request.OwnerUserId, page, pageSize, cancellationToken);
        return OperationResult<PagedResult<SupportAlertDto>>.SuccessResult(result);
    }
}
