<?php
session_start();

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config/config.php';

use App\Controllers\ExamController;

$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$method = $_SERVER['REQUEST_METHOD'];

$controller = new ExamController();

if ($uri === '/' && $method === 'GET') {
    $controller->showForm();
    exit;
}

if ($uri === '/generate' && $method === 'GET') {
    // Redirect GET requests to the form instead of showing 404
    header('Location: /');
    exit;
}

if ($uri === '/generate' && $method === 'POST') {
    $controller->generate();
    exit;
}

if ($uri === '/download/pdf' && $method === 'GET') {
    $controller->downloadPdf();
    exit;
}

if ($uri === '/download/docx' && $method === 'GET') {
    $controller->downloadDocx();
    exit;
}

http_response_code(404);
echo 'Not Found';
