<?php

namespace App\Modules\RoomPassenger\Application\Find;

use App\Modules\RoomPassenger\Application\RoomPassengerResponse;
use App\Modules\RoomPassenger\Domain\IdRoomPassenger;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class FindRoomPassengerQueryHandler implements QueryHandler
{
    public function __construct(private RoomPassengerFinder $finder) {}

    public function __invoke(FindRoomPassengerQuery $query): RoomPassengerResponse
    {
        $model = $this->finder->__invoke(
            new IdRoomPassenger($query->getId()),
            $query->avoidTransaction(),
            $query->lockInShare()
        );
        return new RoomPassengerResponse(
            $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(),
        );
    }
}
