<?php

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

use App\Modules\DefinedService\Location\Application\LocationResponse;
use App\Modules\DefinedService\Location\Domain\IdLocation;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class FindLocationQueryHandler implements QueryHandler
{
    public function __construct(private LocationFinder $finder) {}

    public function __invoke(FindLocationQuery $query): LocationResponse
    {
        $model = $this->finder->__invoke(new IdLocation($query->getId()), true);
        return new LocationResponse(
            $model->id()->value(),
            $model->date()->value(),
            $model->dateUpdate()->value(),
            $model->name()->value(),
            $model->abrv()->value(),
            $model->latitude()->value(),
            $model->longitude()->value(),
            $model->version()->value(),
            $model->status()->value(),
        );
    }
}
