#pragma once

// Disable windows mess from system headers
#ifndef WIN32_LEAN_AND_MEAN
#  define WIN32_LEAN_AND_MEAN
#endif

#include "IHttpServer.h"

#include <Windows.h>
#include <memory>
#include <mutex>
#include <sdi_toolBox/external/httplib/httplib.h>
#include <thread>

//--------------------------------------------------------------
class HttpServer : public IHttpServer
{
  public:
  HttpServer() = default;                                        // Default constructor
  virtual ~HttpServer();                                         // Default destructor
  HttpServer(const HttpServer &obj)                = delete;     // Copy constructor
  HttpServer(HttpServer &&obj) noexcept            = delete;     // Move constructor
  HttpServer &operator=(const HttpServer &obj)     = delete;     // Copy assignment operator
  HttpServer &operator=(HttpServer &&obj) noexcept = delete;     // Move assignment operator

  // Server control methods
  void               enable(const std::string &listenAddresses, uint16_t listenPort) override;     // Start the server and listen on the specified address and port
  void               disable() override;                                                           // Stop the server and clean up resources
  [[nodiscard]] bool isEnabled() override;                                                         // Check if the server is currently enabled

  protected:
  struct
  {
    std::mutex                       serverMtx;        // Mutex for synchronizing access to the server
    std::unique_ptr<httplib::Server> hServer;          // Pointer to the HTTP server instance
    std::jthread                     serverThread;     // Thread for running the server
  } m_httpServer;
};
//--------------------------------------------------------------
