#pragma once

#include "ros_bridge/rapidjson/include/rapidjson/document.h"
#include "ros_bridge/include/PackageQueue.h"
#include "ros_bridge/include/CasePacker.h"

#include <memory>
#include <tuple>

#include "boost/lockfree/queue.hpp"

namespace ROSBridge {
namespace lf = ::boost::lockfree;
class Communicator : protected CasePacker
{
    typedef MessageTag Tag;
    typedef rapidjson::Document JsonDoc;
    typedef std::shared_ptr<JsonDoc> JsonDocShardPtr;
    typedef PackageQueue<JsonDocShardPtr> Buffer;
    //typedef std::tuple<UniqueJsonPtr, std::string> MsgTopicHashPair;
public:
  explicit Communicator() : CasePacker() {}

    template<class T>
    void send(T &msg, std::string &topic){
        JsonDocShardPtr docPtr(CasePacker::pack(msg, topic));
        _transmittBuffer.push(docPtr);
    }

    void start();
    void stop();
    bool messagesAvailable();
    bool showMessageTag(Tag &tag);
    template<class T>
    void receive(T &msg){

    }

private:
    Buffer              _transmittBuffer;
    Buffer              _receiveBuffer;
    JsonDocShardPtr     _stagedMessage; // message awaiting delivery
};
}
