<?php
/**
 * Container health check (Coolify / Docker HEALTHCHECK).
 */
header('Content-Type: application/json; charset=utf-8');

require __DIR__ . '/config.php';

try {
    if (!extension_loaded('pdo_pgsql')) {
        throw new RuntimeException('pdo_pgsql extension missing');
    }
    require_once __DIR__ . '/helpers.php';
    require_database();
    $response = ['status' => 'ok'];
    echo json_encode($response, JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
    http_response_code(503);
    $response = [
        'status' => 'error',
        'message' => $e->getMessage(),
    ];
    echo json_encode($response, JSON_UNESCAPED_UNICODE);
    exit(1);
}
