<?php

declare(strict_types=1);

namespace App\Framework\Mcp\Tools;

use App\Framework\Mcp\McpTool;
use App\Framework\Router\CompiledRoutes;
use App\Framework\Router\RouteInspector;

/**
 * MCP tool exposing routing sanity checks
 */
final readonly class RouteInspectorTool
{
    public function __construct(
        private CompiledRoutes $compiledRoutes
    ) {
    }

    #[McpTool(
        name: 'route_sanity_check',
        description: 'Analyze compiled routes for common issues (missing controllers/actions, parameter mismatches, duplicates)'
    )]
    public function routeSanityCheck(): array
    {
        try {
            $inspector = new RouteInspector($this->compiledRoutes);

            return $inspector->analyze();
        } catch (\Throwable $e) {
            return [
                'error' => $e->getMessage(),
            ];
        }
    }
}
