#nullable enable
using Baya.Application.Contracts.Persistence;
using Baya.Application.Models.Booking;
using Baya.Application.Models.Common;
using Mediator;

namespace Baya.Application.Features.Bookings.Queries.ListAdminEvv;

// Admin-only access is enforced by the controller policy; this handler assumes an admin caller.
internal sealed class ListAdminEvvQueryHandler(IUnitOfWork unitOfWork)
    : IRequestHandler<ListAdminEvvQuery, OperationResult<PagedResult<AdminEvvItemDto>>>
{
    public async ValueTask<OperationResult<PagedResult<AdminEvvItemDto>>> Handle(ListAdminEvvQuery request, CancellationToken cancellationToken)
    {
        var page = request.Page < 1 ? 1 : request.Page;
        var pageSize = request.PageSize is < 1 or > 100 ? 20 : request.PageSize;
        var type = request.Type == "no_show" ? "no_show" : "mismatch";

        var result = await unitOfWork.BookingRepository.ListAdminEvvAsync(type, page, pageSize, cancellationToken);
        return OperationResult<PagedResult<AdminEvvItemDto>>.SuccessResult(result);
    }
}
