<?php
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../config/constants.php';
require_once __DIR__ . '/../../includes/functions.php';
require_once __DIR__ . '/../../includes/auth_admin.php';
require_once __DIR__ . '/../../includes/audit.php';

apply_cors();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    send_error('Method not allowed.', 405);
}

$admin = require_admin();
$token = get_bearer_token();
destroy_admin_session($token);

log_admin_action($admin['email'], 'ADMIN_LOGOUT', $admin['email'], '');

send_success(null, 'Logged out successfully.');
