package com.zioinfo.mes.integration;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * GUARDiA BI 연계 — 생산/품질/재고 KPI를 BI 데이터 피드로 push.
 */
@Component
@RequiredArgsConstructor
public class BiClient {

    @Value("${guardia.bi-url:http://localhost:8006}")
    private String biUrl;

    private final GuardiaHttpClient http;

    /** KPI 스냅샷을 BI 피드로 전송(연계 실패 시 무시). */
    public Map<String, Object> pushKpiFeed(Map<String, Object> kpi) {
        return http.callMap(biUrl, "/api/bi/feed/mes", HttpMethod.POST, kpi);
    }

    public boolean available() {
        return !http.callMap(biUrl, "/actuator/health", HttpMethod.GET, null).isEmpty();
    }
}
