<?php

require '/var/www/html/vendor/autoload.php';

use App\Framework\Discovery\DiscoveryServiceBootstrapper;
use App\Framework\DI\DefaultContainer;
use App\Framework\Attributes\Route;

try {
    echo "=== Route Discovery Diagnostic ===\n";

    $container = new DefaultContainer();
    $bootStrapper = new DiscoveryServiceBootstrapper();
    $bootStrapper->initialize($container);

    $registry = $container->get('App\Framework\Discovery\Results\DiscoveryRegistry');
    $routes = $registry->attributes->get(Route::class);

    echo "Total routes found: " . count($routes) . "\n\n";

    $adminRoutes = [];
    foreach ($routes as $route) {
        $path = $route->additionalData['path'] ?? '';
        if (str_contains($path, 'admin')) {
            $adminRoutes[] = [
                'path' => $path,
                'controller' => $route->className->getFullyQualified(),
                'method' => $route->methodName?->toString() ?? 'unknown'
            ];
        }
    }

    echo "Admin routes found:\n";
    foreach ($adminRoutes as $route) {
        echo "  Path: {$route['path']}\n";
        echo "  Controller: {$route['controller']}\n";
        echo "  Method: {$route['method']}\n";
        echo "  ---\n";
    }

    // Check specifically for ShowRoutes
    echo "\nLooking for ShowRoutes controller:\n";
    foreach ($routes as $route) {
        if (str_contains($route->className->getFullyQualified(), 'ShowRoutes')) {
            echo "Found ShowRoutes route:\n";
            echo "  Path: " . ($route->additionalData['path'] ?? 'unknown') . "\n";
            echo "  Controller: " . $route->className->getFullyQualified() . "\n";
            echo "  Method: " . ($route->methodName?->toString() ?? 'unknown') . "\n";
            break;
        }
    }

} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Stack trace: " . $e->getTraceAsString() . "\n";
}