<?php

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

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

final class IndexLocationQueryHandler implements QueryHandler
{
    public function __construct(private LocationIndexer $inserter) {}

    public function __invoke(IndexLocationQuery $query): LocationResponse
    {
        $model = $this->inserter->__invoke(new IdLocation($query->getId()));
        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(),
        );
    }
}
