package com.smyhub.infogenie.infogeniebackendjava.controller;

import com.smyhub.infogenie.infogeniebackendjava.dto.response.HealthResponse;
import com.smyhub.infogenie.infogeniebackendjava.service.HealthService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * GET /          — service banner
 * GET /api/health — component health check
 */
@RestController
@RequiredArgsConstructor
public class HealthController {

    private final HealthService healthService;

    @GetMapping("/")
    public ResponseEntity<Map<String, Object>> root() {
        Map<String, Object> body = new LinkedHashMap<>();
        body.put("service", "InfoGenie Backend");
        body.put("version", "3.3.0-java");
        body.put("status", "running");
        body.put("endpoints", new String[]{
                "GET  /api/health",
                "GET  /api/auth/check",
                "GET  /api/user/profile",
                "GET  /api/site/60s-disabled",
                "GET  /api/site/60s-source",
                "GET  /api/site/ai-model-disabled",
                "GET  /api/site/feature-card-clicks",
                "POST /api/site/feature-card-clicks/increment",
                "GET  /api/admin/site/diagnostics",
                "POST /api/aimodelapp/chat",
                "POST /api/aimodelapp/chat/stream",
                "GET  /api/aimodelapp/models"
        });
        return ResponseEntity.ok(body);
    }

    /**
     * Same as Go: always HTTP 200; degradation is expressed only in JSON {@code status} field.
     * AdminPage treats non-2xx as a failed fetch and clears the monitoring payload.
     */
    @GetMapping("/api/health")
    public ResponseEntity<HealthResponse> health() {
        return ResponseEntity.ok(healthService.buildHealthResponse());
    }
}
