<?php

namespace App\Modules\Room\Application\List;

use App\Modules\Room\Application\RoomResponse;
use App\Modules\Room\Application\RoomResponses;
use App\Modules\Room\Domain\Room;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class ListRoomQueryHandler implements QueryHandler
{
    public function __construct(private RoomLister $lister) {}

    public function __invoke(ListRoomQuery $query): RoomResponses
    {
        $list = $this->lister->__invoke(
            $query->action,
            $query->idBookingExtra,
        );
        return new RoomResponses(
            ...array_map(fn(Room $model) => $model->toDTO(RoomResponse::class), $list)
        );
    }
}
