<?php

namespace App\Http\Controllers;

use App\Core\Request;
use App\Core\Response;
use App\Drivers\DatabaseDriver;

class HealthController
{
    public function __construct(private DatabaseDriver $db)
    {
    }

    public function check(Request $request): Response
    {
        return Response::json([
            'service' => 'auth-microservice',
            'status' => 'running',
            'version' => $_ENV['SERVICE_VERSION'] ?? '1.0.0',
            'database' => $this->db->testConnection() ? 'connected' : 'unavailable',
            'keys' => [
                'private' => is_readable(dirname(__DIR__, 3) . '/app/Keys/private.pem'),
                'public' => is_readable(dirname(__DIR__, 3) . '/app/Keys/public.pem'),
            ],
            'timestamp' => date('c'),
        ]);
    }
}
