<?php

namespace App\Modules\TypeRoom\Application\Find;

use App\Modules\TypeRoom\Application\TypeRoomResponse;
use App\Modules\TypeRoom\Domain\IdTypeRoom;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class FindTypeRoomQueryHandler implements QueryHandler
{
    public function __construct(private TypeRoomFinder $finder) {}

    public function __invoke(FindTypeRoomQuery $query): TypeRoomResponse
    {
        $model = $this->finder->__invoke(
            new IdTypeRoom($query->getId()),
            $query->avoidTransaction(),
            $query->lockInShare()
        );
        return new TypeRoomResponse(
            $model->id()->value(),
            $model->name()->value(),
            $model->abrv()->value(),
            $model->capacity()->value(),
            $model->status()->value(),
        );
    }
}
