// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/PrometheusFormatWriter.java
// public class PrometheusFormatWriter {
//     private final StringWriter writer = new StringWriter();
//     private final Map<String, String> globalLabels;
// 
//     public PrometheusFormatWriter(Map<String, String> globalLabels) {
//         this.globalLabels = globalLabels;
//     }
// 
//     public SingleMetricsDefinitionBuilder addGauge(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.GAUGE, writer, name, globalLabels);
//     }
// 
//     public SingleMetricsDefinitionBuilder addCounter(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.COUNTER, writer, name, globalLabels);
//     }
// 
//     public SummaryMetricsDefinitionBuilder addSummary(String name) {
//         return new SummaryMetricsDefinitionBuilder(writer, name, globalLabels);
//     }
// 
//     public String toString() {
//         return writer.toString();
//     }
// }


import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.PrometheusFormatWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
package pl.suchenia.elasticsearchPrometheusMetrics.generators;



public abstract class MetricsGenerator<T> {
    private static final Logger logger = Loggers.getLogger(MetricsGenerator.class, "init");

    static double getDynamicValue(Object obj, String methodName) {
        try {
            Method method = obj.getClass().getMethod(methodName);
            Object value = method.invoke(obj);
            if (value.getClass().isAssignableFrom(Long.class)) {
                Long l = (Long) value;
                return l.doubleValue();
            }
            return (double) value;
        } catch (NoSuchMethodException e) {
            logger.error("There are no getTotalSizeInBytes method defined");
            return -1.0;
        } catch (IllegalAccessException | InvocationTargetException | ClassCastException e) {
            logger.error("Exception during method invocation: {}", e.getMessage());
            return -1.0;
        }
    }
// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/writer/PrometheusFormatWriter.java
// public class PrometheusFormatWriter {
//     private final StringWriter writer = new StringWriter();
//     private final Map<String, String> globalLabels;
// 
//     public PrometheusFormatWriter(Map<String, String> globalLabels) {
//         this.globalLabels = globalLabels;
//     }
// 
//     public SingleMetricsDefinitionBuilder addGauge(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.GAUGE, writer, name, globalLabels);
//     }
// 
//     public SingleMetricsDefinitionBuilder addCounter(String name) {
//         return new SingleMetricsDefinitionBuilder(MetricType.COUNTER, writer, name, globalLabels);
//     }
// 
//     public SummaryMetricsDefinitionBuilder addSummary(String name) {
//         return new SummaryMetricsDefinitionBuilder(writer, name, globalLabels);
//     }
// 
//     public String toString() {
//         return writer.toString();
//     }
// }


// Path: elasticsearch-plugin/src/main/java/pl/suchenia/elasticsearchPrometheusMetrics/generators/MetricsGenerator.java
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import pl.suchenia.elasticsearchPrometheusMetrics.writer.PrometheusFormatWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

package pl.suchenia.elasticsearchPrometheusMetrics.generators;



public abstract class MetricsGenerator<T> {
    private static final Logger logger = Loggers.getLogger(MetricsGenerator.class, "init");

    static double getDynamicValue(Object obj, String methodName) {
        try {
            Method method = obj.getClass().getMethod(methodName);
            Object value = method.invoke(obj);
            if (value.getClass().isAssignableFrom(Long.class)) {
                Long l = (Long) value;
                return l.doubleValue();
            }
            return (double) value;
        } catch (NoSuchMethodException e) {
            logger.error("There are no getTotalSizeInBytes method defined");
            return -1.0;
        } catch (IllegalAccessException | InvocationTargetException | ClassCastException e) {
            logger.error("Exception during method invocation: {}", e.getMessage());
            return -1.0;
        }
    }
    public abstract PrometheusFormatWriter generateMetrics(PrometheusFormatWriter writer, T inputData);