<?php

namespace App\Modules\DefinedService\Route\Application\List;

use App\Modules\DefinedService\Route\Application\RouteResponse;
use App\Modules\DefinedService\Route\Application\RouteResponses;
use App\Modules\DefinedService\Route\Domain\RouteDescription;
use App\Modules\Shared\Domain\Bus\Query\QueryHandler;

final class ListRouteQueryHandler implements QueryHandler
{
    public function __construct(private RouteLister $lister) {}

    public function __invoke(ListRouteQuery $query): RouteResponses
    {
        return new RouteResponses(...array_map(
            fn($index) => new RouteResponse(
                $index->id()->value(),
                $index->date()->value(),
                $index->dateUpdate()->value(),
                $index->description()->value(),
                $index->version()->value(),
                $index->status()->value(),
                $index->idLocationStart()->value(),
                $index->idLocationEnd()->value(),
                $index->idTypeDefinedService()->value()
            ),
            $this->lister->__invoke(new RouteDescription($query->description()), $query->action())
        ));
    }
}
