<?php

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

use App\Modules\DefinedService\Location\Domain\IdLocation;
use App\Modules\DefinedService\Location\Domain\LocationAbrv;
use App\Modules\DefinedService\Location\Domain\LocationDate;
use App\Modules\DefinedService\Location\Domain\LocationDateUpdate;
use App\Modules\DefinedService\Location\Domain\LocationLatitude;
use App\Modules\DefinedService\Location\Domain\LocationLongitude;
use App\Modules\DefinedService\Location\Domain\LocationName;
use App\Modules\DefinedService\Location\Domain\LocationStatus;
use App\Modules\DefinedService\Location\Domain\LocationVersion;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class InsertLocationQueryHandler implements QueryHandler
{
    public function __construct(private LocationInserter $inserter) {}

    public function __invoke(InsertLocationQuery $query): InsertLocationResponse
    {
        return new InsertLocationResponse($this->inserter->__invoke(
            new IdLocation(0),
            new LocationDate($query->date()),
            new LocationDateUpdate($query->dateUpdate()),
            new LocationName($query->name()),
            new LocationAbrv($query->abrv()),
            new LocationLatitude($query->latitude()),
            new LocationLongitude($query->longitude()),
            new LocationVersion(1),
            new LocationStatus($query->status()),
            $query->idAdmin()
        ));
    }
}
