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

namespace Baya.Application.Features.Holidays.Queries.ListHolidays;

internal sealed class ListHolidaysQueryHandler(IHolidayCalendar holidayCalendar)
    : IRequestHandler<ListHolidaysQuery, OperationResult<PagedResult<HolidayDto>>>
{
    public async ValueTask<OperationResult<PagedResult<HolidayDto>>> Handle(ListHolidaysQuery request, CancellationToken cancellationToken)
    {
        var (page, pageSize) = Pagination.Normalize(request.Page, request.PageSize);
        var result = await holidayCalendar.ListAsync(request.From, request.To, page, pageSize, cancellationToken);
        return OperationResult<PagedResult<HolidayDto>>.SuccessResult(result);
    }
}
