using MediatR;
using FnbEngine.Domain.AggregatesModel.ReservationAggregate;

namespace FnbEngine.API.Application.Queries;

public class GetReservationsQueryHandler : IRequestHandler<GetReservationsQuery, IEnumerable<ReservationDto>>
{
    private readonly IReservationRepository _reservationRepository;

    public GetReservationsQueryHandler(IReservationRepository reservationRepository)
    {
        _reservationRepository = reservationRepository ?? throw new ArgumentNullException(nameof(reservationRepository));
    }

    public async Task<IEnumerable<ReservationDto>> Handle(GetReservationsQuery request, CancellationToken cancellationToken)
    {
        var reservations = await _reservationRepository.GetByShopAsync(request.ShopId, request.Date, cancellationToken);

        return reservations.Select(r => new ReservationDto(
            r.Id, r.ShopId, r.TableId, r.GuestName, r.Phone,
            r.PartySize, r.ReservationTime, r.Status, r.Note, r.CreatedAt));
    }
}
