#pragma once




#include "WHISPER/threadSafeQueue.hpp"
#include "zmq.hpp"
#include <atomic>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <sys/types.h>
#include <thread>
#include <vector>



namespace DirectCommunication 
{

    class DirectCommunicationClient
    {
        public:
            DirectCommunicationClient(ushort port, std::string ServerAddress);
            ~DirectCommunicationClient();

            void sendMessage(std::string msg);
            std::string getLatestMessage();
            void disconnect();

            void registerMessageCallback(std::function<void(std::string)> MessageHandle);


        private:
            ushort port_;
            std::string serverAddress_;

            zmq::context_t context_;
            zmq::socket_t socket_;

            void workerFunc_();
            std::thread Worker_;
            std::atomic_bool stopWorker_;

            std::atomic_bool isConnected = false;

            std::function<void(std::string)> MessageHandle_ = nullptr;
            std::atomic_bool useHandl_ = false;;

            WHISPER::threadSafeQueue<std::string> receivedMessages_;


            
    };


}