<?php
/**
 * Export the whole SQLite database as a file download.
 *
 * Thin dispatcher — delegates to ExportController.
 */
require_once __DIR__ . "/../../../bootstrap.php";
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();

require_once APP_ROOT . '/src/Controllers/ExportController.php';
$controller = ExportController::create();

$dbPath = $controller->getDatabasePath();

if (!file_exists($dbPath)) {
    http_response_code(500);
    exit('Base de données introuvable.');
}

$filename = 'posterg-db-' . date('Y-m-d') . '.sqlite';

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: ' . filesize($dbPath));
header('Cache-Control: no-cache, must-revalidate');

readfile($dbPath);
exit;
