<?php

namespace App\Http\Controllers\Api\System;

use App\Http\Controllers\Api\Core\BaseApiController;
use App\Services\System\HealthCheckService;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class HealthController extends BaseApiController
{
    public function __construct(private HealthCheckService $service)
    {
        parent::__construct();
    }

    public function index(): JsonResponse
    {
        $payload = $this->service->check();
        $status = $payload['ok'] ? Response::HTTP_OK : Response::HTTP_SERVICE_UNAVAILABLE;

        // legacy admin/API health returns a flat JSON body (no Laravel success envelope).
        return response()->json($payload, $status);
    }
}
