<?php
/**
 * NIS2 Agile - Health Check
 */

header('Content-Type: application/json');

$status = [
    'status'    => 'ok',
    'app'       => 'NIS2 Agile',
    'version'   => '1.0.0',
    'timestamp' => date('c'),
    'checks'    => [],
];

// Database check
try {
    require_once __DIR__ . '/../application/config/config.php';
    require_once __DIR__ . '/../application/config/database.php';

    Database::fetchOne('SELECT 1');
    $status['checks']['database'] = 'ok';
} catch (Throwable $e) {
    $status['checks']['database'] = 'error';
    $status['status'] = 'degraded';
}

http_response_code($status['status'] === 'ok' ? 200 : 503);
echo json_encode($status, JSON_PRETTY_PRINT);
