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

namespace Baya.Application.Features.PartnerCenters.Queries.GetCenterForBooking;

internal sealed class GetCenterForBookingQueryHandler(IUnitOfWork unitOfWork)
    : IRequestHandler<GetCenterForBookingQuery, OperationResult<CenterForBookingDto>>
{
    public async ValueTask<OperationResult<CenterForBookingDto>> Handle(GetCenterForBookingQuery request, CancellationToken cancellationToken)
    {
        var resolution = await unitOfWork.PartnerCenterRepository.ResolveCenterForBookingAsync(request.BookingId, cancellationToken);
        return resolution is null
            ? OperationResult<CenterForBookingDto>.NotFoundResult("Booking not found.")
            : OperationResult<CenterForBookingDto>.SuccessResult(resolution);
    }
}
