<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Core\Database;
use App\Core\Env;
use App\Core\Request;
use App\Core\Response;
use Throwable;

final class HealthController
{
    public function index(Request $request, array $params = []): void
    {
        $db = 'offline';
        try {
            Database::fetchOne('SELECT 1 AS ok');
            $db = 'online';
        } catch (Throwable) {
            $db = 'offline';
        }

        Response::json([
            'status' => 'ok',
            'app' => Env::get('APP_NAME', 'SISPROM PHP API'),
            'backend' => 'php',
            'database' => $db,
            'time' => date(DATE_ATOM),
        ]);
    }
}
