<?php

declare(strict_types=1);

require dirname(__DIR__) . '/bootstrap.php';

use App\Support\Diagnostics;

$includeHttp = in_array('--http', $argv, true);
$checks = Diagnostics::run($includeHttp);
$summary = Diagnostics::summarize($checks);

$paint = static function (string $status): string {
    return match ($status) {
        'ok' => "\033[32mOK\033[0m",
        'warning' => "\033[33mWARN\033[0m",
        default => "\033[31mFALHA\033[0m",
    };
};

echo "\n=== Pré-flight do sistema de admissões ===\n\n";
foreach ($checks as $check) {
    echo sprintf("[%s] %-24s | %-28s | %s\n", $paint($check['status']), strtoupper($check['group']), $check['label'], $check['details']);
}

echo "\nResumo: OK={$summary['ok']} | Warning={$summary['warning']} | Falhas={$summary['error']}\n";

exit($summary['error'] > 0 ? 1 : 0);
