#include "metrics_manager.hpp"

MetricsManager::MetricsManager() {}

MetricsManager::MetricsManager(const std::string& address)
    : address_prometheus(address)  // <- initialize const member here
{}
void MetricsManager::setup_prometheus() {
    // Start the HTTP server on 0.0.0.0:8080
    exposer = std::make_unique<prometheus::Exposer>(address_prometheus);

    // Set up Prometheus as before...
    registry = std::make_shared<prometheus::Registry>();
    gauge_family = &prometheus::BuildGauge()
                        .Name("frame_delay")
                        .Help("Delay between frames")
                        .Register(*registry);

    my_gauge = &gauge_family->Add({{"source", "camera1"}});

    counter_family = &prometheus::BuildCounter()
                          .Name("frames_received_total")
                          .Help("Total frames received")
                          .Register(*registry);

    counter = &counter_family->Add({{"label", "value"}});
    exposer->RegisterCollectable(registry);
}

void MetricsManager::metrics_loop() {  // prometheus::Gauge *my_gauge
    while (running) {
        // std::cout << "metrics_loop" << std::endl;
        counter->Increment();
        // simulate updating a metric
        my_gauge->Set(static_cast<double>(rand() % 100));
        std::this_thread::sleep_for(std::chrono::seconds(2));
    }
}

MetricsManager::~MetricsManager() {
    std::cout << "MetricsManager destroyed" << std::endl;
}
