<?php
header('Content-Type: application/json; charset=utf-8');

require_once dirname(__DIR__) . '/config/config.php';
require_once dirname(__DIR__) . '/includes/db.php';
require_once dirname(__DIR__) . '/includes/functions.php';
require_once dirname(__DIR__) . '/includes/auth.php';
require_once dirname(__DIR__) . '/includes/api.php';

$auth = apiAuthContext();
$user = $auth['admin_user'];
$data = [
    'authenticated' => (bool)$auth['authenticated'],
    'auth_type' => $auth['auth_type'],
    'token_present' => (bool)$auth['token_present'],
    'token_supported' => (bool)$auth['token_supported'],
    'token_error' => $auth['token_error'] ?? null,
    'token_id' => isset($auth['token_id']) ? (int)$auth['token_id'] : null,
    'user' => $user ? [
        'id' => (int)$user['id'],
        'username' => ensureUtf8String($user['username'] ?? ''),
        'display_name' => ensureUtf8String($user['display_name'] ?? ''),
        'role' => ensureUtf8String($user['role'] ?? ''),
    ] : null,
];

apiSuccess($data);
