<?php
declare(strict_types=1);
require_once __DIR__ . '/app.php';
header('Content-Type: application/json; charset=utf-8');

try {
    db()->query('SELECT 1');
    echo json_encode([
        'status' => 'ok',
        'app' => project_name(),
        'time_utc' => gmdate('c'),
        'database' => 'connected',
        'client_ip' => client_ip(),
    ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
} catch (Throwable $exception) {
    http_response_code(500);
    echo json_encode([
        'status' => 'error',
        'app' => project_name(),
        'time_utc' => gmdate('c'),
        'database' => 'disconnected',
        'error' => $exception->getMessage(),
    ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
}
