#pragma once

#include "application.hpp"

#include <atomic>
#include <string>

#include <httplib.h>
#include <nlohmann/json.hpp>

class HttpServer
{
public:
    HttpServer(Application &application, std::string host, int port, std::string web_root);

    bool run();
    void stop();

private:
    static void sendJson(httplib::Response &response, const nlohmann::json &body, int status = 200);
    static nlohmann::json parseJson(const httplib::Request &request);
    static std::size_t cameraIndex(const httplib::Request &request);
    void registerRoutes();

    Application &application_;
    std::string host_;
    int port_;
    std::string web_root_;
    httplib::Server server_;
    std::atomic<bool> running_{false};
};

