<?php
declare(strict_types=1);

require_once __DIR__ . '/../config/constants.php';
require_once __DIR__ . '/../core/Response.php';

session_name(SESSION_NAME);
session_start();

/**
 * Generate CSRF token if missing
 */
if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}

/**
 * Return token as JSON only
 */
Response::success('CSRF token generated', [
    'csrf_token' => $_SESSION['csrf_token']
]);
