<?php

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

use App\Modules\DefinedService\TypeDefinedService\Domain\IdTypeDefinedService;
use App\Modules\DefinedService\TypeDefinedService\Domain\TypeDefinedServiceCode;
use App\Modules\DefinedService\TypeDefinedService\Domain\TypeDefinedServiceDate;
use App\Modules\DefinedService\TypeDefinedService\Domain\TypeDefinedServiceDateUpdate;
use App\Modules\DefinedService\TypeDefinedService\Domain\TypeDefinedServiceName;
use App\Modules\DefinedService\TypeDefinedService\Domain\TypeDefinedServiceStatus;
use App\Modules\DefinedService\TypeDefinedService\Domain\TypeDefinedServiceVersion;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;
use App\Modules\TypeProvider\Domain\IdTypeProvider;

final class InsertTypeDefinedServiceQueryHandler implements QueryHandler
{
    public function __construct(private TypeDefinedServiceInserter $inserter) {}

    public function __invoke(InsertTypeDefinedServiceQuery $query): InsertTypeDefinedServiceResponse
    {
        return new InsertTypeDefinedServiceResponse($this->inserter->__invoke(
            new IdTypeDefinedService(0),
            new TypeDefinedServiceDate($query->date()),
            new TypeDefinedServiceDateUpdate($query->dateUpdate()),
            new TypeDefinedServiceName($query->name()),
            new TypeDefinedServiceCode($query->code()),
            new TypeDefinedServiceVersion(1),
            new TypeDefinedServiceStatus($query->status()),
            new IdTypeProvider($query->idTypeProvider()),
            $query->idAdmin()
        ));
    }
}
