<?php

namespace App\Modules\Room\Application\Index;

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

final class IndexRoomQueryHandler implements QueryHandler
{
    public function __construct(private RoomIndexer $indexer) {}

    public function __invoke(IndexRoomQuery $query): RoomResponse
    {
        $index = $this->indexer->__invoke(
            new IdRoom($query->id()),
            new IndexRoomPopulate($query->populate())
        );
        return $index->toDTO(RoomResponse::class);
    }
}
