<?php

declare(strict_types=1);

use App\Controllers\AdminAdmissionController;
use App\Controllers\AdminAuthController;
use App\Controllers\AdminDiagnosticsController;
use App\Controllers\AdminUserController;
use App\Controllers\AdmissionController;
use Core\Router;

require dirname(__DIR__) . '/bootstrap.php';

$router = new Router();
$router->get('/', [AdmissionController::class, 'create']);
$router->post('/admissoes', [AdmissionController::class, 'store']);
$router->get('/obrigado', [AdmissionController::class, 'success']);
$router->get('/admin/login', [AdminAuthController::class, 'login']);
$router->post('/admin/login', [AdminAuthController::class, 'authenticate']);
$router->get('/admin/logout', [AdminAuthController::class, 'logout']);
$router->get('/admin/diagnostico', [AdminDiagnosticsController::class, 'index']);
$router->get('/admin/usuarios', [AdminUserController::class, 'index']);
$router->get('/admin/usuarios/novo', [AdminUserController::class, 'create']);
$router->post('/admin/usuarios', [AdminUserController::class, 'store']);
$router->get('/admin/usuarios/{id}/editar', [AdminUserController::class, 'edit']);
$router->post('/admin/usuarios/{id}/editar', [AdminUserController::class, 'update']);
$router->post('/admin/usuarios/{id}/status', [AdminUserController::class, 'toggleStatus']);
$router->get('/admin/admissoes', [AdminAdmissionController::class, 'index']);
$router->get('/admin/admissoes/{id}', [AdminAdmissionController::class, 'show']);
$router->get('/admin/admissoes/{id}/editar', [AdminAdmissionController::class, 'edit']);
$router->post('/admin/admissoes/{id}/editar', [AdminAdmissionController::class, 'update']);
$router->get('/admin/admissoes/{id}/imprimir', [AdminAdmissionController::class, 'print']);
$router->get('/admin/admissoes/{id}/pdf', [AdminAdmissionController::class, 'pdf']);
$router->post('/admin/admissoes/{id}/status', [AdminAdmissionController::class, 'updateStatus']);
$router->get('/admin/admissoes/{id}/excluir', [AdminAdmissionController::class, 'confirmDestroy']);
$router->post('/admin/admissoes/{id}/excluir', [AdminAdmissionController::class, 'destroy']);
$router->get('/admin/admissoes/{id}/anexos/{attachmentId}/visualizar', [AdminAdmissionController::class, 'previewAttachment']);
$router->get('/admin/admissoes/{id}/anexos/{attachmentId}/download', [AdminAdmissionController::class, 'downloadAttachment']);

$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?: '/';
$scriptName = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
$basePath = rtrim($scriptName, '/');
if ($basePath !== '' && $basePath !== '/') $uri = preg_replace('#^' . preg_quote($basePath, '#') . '#', '', $uri) ?: '/';
$router->dispatch($_SERVER['REQUEST_METHOD'], $uri);
