package com.smyhub.infogenie.infogeniebackendjava.dto.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

/**
 * Matches Go {@code GET /api/health} JSON so the admin UI ({@code normalizeHealthPayload}) parses it.
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class HealthResponse {

    private String status;
    private String timestamp;

    /**
     * Go uses {@code "connected"} / {@code "disconnected"}; frontend falls back to {@code mysql.ok}.
     */
    private String database;

    private MysqlHealth mysql;

    private RedisHealth redis;

    @JsonProperty("backend_api")
    private BackendApiHealth backendApi;

    @JsonProperty("sixty_api")
    private SixtyApiHealth sixtyApi;

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class MysqlHealth {
        private boolean ok;
        private String status;
    }

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class RedisHealth {
        private boolean enabled;
        private Boolean ok;
        private String error;
    }

    @Data
    public static class BackendApiHealth {
        private boolean ok = true;
    }

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class SixtyApiHealth {
        private boolean ok;

        @JsonProperty("source_id")
        private String sourceId;

        @JsonProperty("base_url")
        private String baseUrl;

        private String label;

        @JsonProperty("probe_url")
        private String probeUrl;

        @JsonProperty("http_status")
        private int httpStatus;

        @JsonProperty("latency_ms")
        private long latencyMs;

        private String error;
    }
}
