<?php

declare(strict_types=1);

namespace apexl\Io\modules\system\services;

use apexl\Io\includes\RouteManager;

final readonly class RouteDebugHelper
{
    public function __construct(private RouteManager $routeManager) {}

    function routes(): array
    {
        $routeNames = $this->routeManager->routes;

        $routes = [];
        foreach ($routeNames as $name => $object) {
            $args = $object->getArgs();
            $moduleName = $args['moduleName'] ?? 'Core';
            if (!isset($routes[$moduleName])) {
                $routes[$moduleName] = [];
            }

            $routes[$moduleName][] = [
                'verb' => $object->getMethod()->name,
                'pattern' => $object->getPattern(stripTags: false),
                'name' => $name,
                'callable' => $object->getCallable(),
                'args' => $object->getArgs(),
            ];
        }

        return $routes;
    }
}