<?php
require_once __DIR__ . '/../controllers/SecurityController.php';

// Crear instancia del controlador
$controller = new SecurityController();

// Manejar rutas de seguridad
$method = $_SERVER['REQUEST_METHOD'];
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

// Extraer la acción de la URL
$pathParts = explode('/', trim($path, '/'));
$action = $pathParts[2] ?? null; // security/{action}

switch ($method) {
    case 'GET':
        if ($action === 'stats') {
            // GET /api/security/stats
            echo $controller->getSecurityStats();
        } elseif ($action === 'audit') {
            // GET /api/security/audit
            echo $controller->audit();
        } else {
            http_response_code(404);
            echo json_encode([
                'success' => false,
                'message' => 'Endpoint no encontrado'
            ]);
        }
        break;
        
    case 'POST':
        if ($action === 'cleanup') {
            // POST /api/security/cleanup
            echo $controller->cleanup();
        } else {
            http_response_code(404);
            echo json_encode([
                'success' => false,
                'message' => 'Endpoint no encontrado'
            ]);
        }
        break;
        
    default:
        http_response_code(405);
        echo json_encode([
            'success' => false,
            'message' => 'Método no permitido'
        ]);
        break;
}