<?php
declare(strict_types=1);

require_once __DIR__ . '/../../config/constants.php';
require_once __DIR__ . '/../../core/Response.php';
require_once __DIR__ . '/../../security/auth_guard_api.php';
// Optional but recommended
// require_once __DIR__ . '/../../security/csrf_guard.php';

session_name(SESSION_NAME);
session_start();

$_SESSION = [];
session_destroy();

if (ini_get('session.use_cookies')) {
    $params = session_get_cookie_params();

    setcookie(
        session_name(),
        '',
        time() - 42000,
        $params['path'],
        $params['domain'],
        $params['secure'],
        $params['httponly']
    );
}

session_start();
session_regenerate_id(true);

Response::success('Logged out successfully');
