package com.microservices.mon.k8s.domain.vo;

import lombok.Data;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

@Data
public class PrometheusResVo {
    // 状态（success代表成功）
    String status;
    // 数据
    PrometheusDataVo data;

    public boolean isSuccess() {
        return "success".equals(status)
                && data != null
                && data.getResult() != null
                && !data.getResult().isEmpty();
    }

    public static String getPromStringValue(PrometheusResVo prometheusResVo) {
        String value = "";
        if (prometheusResVo != null && prometheusResVo.isSuccess()) {
            PrometheusResultVo result = prometheusResVo.getData().getResult().get(0);
            return result.getValue().getString(1);
        }
        return value;
    }

    public static List<PrometheusResultVo> getPrometheusResultVoList(PrometheusResVo prometheusResVo) {
        if (prometheusResVo != null && prometheusResVo.isSuccess()) {
            return prometheusResVo.getData().getResult();
        }
        return Collections.emptyList();
    }
}
