<?php

namespace App\Modules\TypeProvider\Application\Index;

use App\Modules\TypeProvider\Application\TypeProviderResponse;
use App\Modules\TypeProvider\Domain\IdTypeProvider;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class IndexTypeProviderQueryHandler implements QueryHandler
{
    public function __construct(private TypeProviderIndexer $inserter) {}

    public function __invoke(IndexTypeProviderQuery $query): TypeProviderResponse
    {
        $model = $this->inserter->__invoke(new IdTypeProvider($query->getId()));
        return new TypeProviderResponse(
            $model->id()->value(),
            $model->name()->value(),
            $model->abrv()->value(),
            $model->endorser()->value(),
            $model->lock()->value(),
            $model->status()->value(),
        );
    }
}
