<?php

namespace App\Modules\DefinedService\Route\Application\Find;

use App\Modules\DefinedService\Route\Application\RouteResponse;
use App\Modules\DefinedService\Route\Domain\IdRoute;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class FindRouteQueryHandler implements QueryHandler
{
    public function __construct(private RouteFinder $finder) {}

    public function __invoke(FindRouteQuery $query): RouteResponse
    {
        $model = $this->finder->__invoke(
            new IdRoute($query->getId()),
            $query->avoidTransaction(),
            $query->lockInShare()
        );
        return new RouteResponse(
            $model->id()->value(),
            $model->date()->value(),
            $model->dateUpdate()->value(),
            $model->description()->value(),
            $model->version()->value(),
            $model->status()->value(),
            $model->idLocationStart()->value(),
            $model->idLocationEnd()->value(),
            $model->idTypeDefinedService()->value(),
        );
    }
}
