<?php
/**
 * Test des erreurs HTTP réelles dans le back office
 * Lance: php tools/test_backoffice_routes.php
 */

require __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\Process\Process;

$routes = [
    'admin' => [
        '/admin/dashboard',
        '/admin/users',
        '/admin/products',
    ],
    'seller' => [
        '/seller/dashboard',
        '/seller/products',
    ],
    'member' => [
        '/member/dashboard',
        '/member/wallet',
    ],
    'verifier' => [
        '/verifier/dashboard',
        '/verifier/kyc',
    ],
    'community' => [
        '/community/dashboard',
        '/community/blog',
    ],
];

echo "╔════════════════════════════════════════════════════════════════╗\n";
echo "║           TEST DES ROUTES DU BACK OFFICE                      ║\n";
echo "╚════════════════════════════════════════════════════════════════╝\n\n";

foreach ($routes as $namespace => $paths) {
    echo "📂 " . strtoupper($namespace) . "\n";
    
    foreach ($paths as $path) {
        // Construire une requête HTTP test
        $cmd = [
            'c:\\xampp2\\php\\php.exe',
            'artisan',
            'tinker',
            '--execute',
            'echo "test";'
        ];
        
        // Au lieu de faire des requêtes HTTP, vérifions les controllers
        $parts = explode('/', trim($path, '/'));
        $namespace_part = ucfirst($parts[0]);
        if (isset($parts[1])) {
            $controller_name = ucwords(str_replace('-', ' ', $parts[1]));
            $controller_name = str_replace(' ', '', $controller_name) . 'Controller';
            
            $controller_file = __DIR__ . "/../app/Http/Controllers/$namespace_part/{$controller_name}.php";
            
            if (file_exists($controller_file)) {
                // Vérifier la classe
                $content = file_get_contents($controller_file);
                if (strpos($content, 'class ' . $controller_name) !== false) {
                    echo "   ✅ $path → $controller_name\n";
                } else {
                    echo "   ⚠️  $path → $controller_name (classe non trouvée)\n";
                }
            } else {
                echo "   ❌ $path → Fichier manquant: {$controller_name}.php\n";
            }
        }
    }
    echo "\n";
}

echo "═══════════════════════════════════════════════════════════════\n";
echo "✅ Scan complet des routes effectué\n";
echo "═══════════════════════════════════════════════════════════════\n";
