#!/usr/bin/env php
<?php
/**
 * Debug Routes - List all registered routes
 */

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/debug';

// Capture routes during registration
class DebugRouter extends Router {
    public function getRoutes() {
        return $this->routes ?? [];
    }
}

// Override Router class temporarily
class Router {
    public $routes = [];

    public function get($path, $handler) {
        $this->routes[] = ['method' => 'GET', 'path' => $path];
    }

    public function post($path, $handler) {
        $this->routes[] = ['method' => 'POST', 'path' => $path];
    }

    public function put($path, $handler) {
        $this->routes[] = ['method' => 'PUT', 'path' => $path];
    }

    public function delete($path, $handler) {
        $this->routes[] = ['method' => 'DELETE', 'path' => $path];
    }

    public function middleware($m) {}
    public function run() {}
}

// Mock other functions
function requireAuth() { return true; }
function getRequestBody() { return []; }
function getQueryParams() { return []; }

// Mock classes
class AuthService {
    public function getCurrentUser() { return ['id' => 1]; }
    public function hasPermission() { return true; }
    public function logAudit() {}
}
class Response {
    public static function success($data) {}
    public static function error($msg, $code = 400) {}
    public static function json($data) {}
}
class Database {
    public static function getInstance() { return new self(); }
    public function getConnection() {
        $pdo = new stdClass();
        $pdo->prepare = function() { return new stdClass(); };
        return $pdo;
    }
}

require_once __DIR__ . '/app/public/index.php';

echo "=== Registered Routes ===\n\n";

if (isset($router) && method_exists($router, 'routes')) {
    foreach ($router->routes as $route) {
        echo sprintf("%-8s %s\n", $route['method'], $route['path']);
    }
} else {
    echo "Could not access routes\n";
}
