#pragma once

#include <string>
#include <thread>
#include <atomic>
#include <cstdint>
#include <curl/curl.h>
#include <iostream>
#include <nlohmann/json.hpp>

class reHttpPoller {
public:
    reHttpPoller(const std::string& host, long interval_s);
    void setEndpoint(const std::string& endpoint);

    void start();
    void stop();

    ~reHttpPoller() {
        stop();
    }
protected:
    void SendRequests();
    static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp);
    std::atomic<bool> is_running_ = false;
    std::thread worker_;
    std::string url_;
    int interval_;
    nlohmann::json data_;
};