#pragma once

#include "ros_bridge/include/ComPrivateInclude.h"
#include "ros_bridge/include/RosBridgeClient.h"
#include "ros_bridge/include/TypeFactory.h"
#include "ros_bridge/include/CasePacker.h"

#include <unordered_map>

namespace ROSBridge {
namespace ComPrivate {


typedef std::function<void(JsonDocUPtr)> CallbackType;

class TopicSubscriber
{
    typedef std::unordered_map<std::string, std::string> TopicMap;
public:

    TopicSubscriber() = delete;
    TopicSubscriber(CasePacker &casePacker, RosbridgeWsClient &rbc);
    ~TopicSubscriber();

    //! @brief Starts the subscriber.
    void start();

    //! @brief Resets the subscriber.
    void reset();

    //! @return Returns false if a subscription to this topic allready exists.
    //!
    //! @note Only one callback can be registered.
    void subscribe(const char* topic, const CallbackType &callback);

private:



    CasePacker         &_casePacker;
    RosbridgeWsClient  &_rbc;
    TopicMap            _topicMap;
    std::shared_ptr<std::atomic_bool>   _stopped;
};

} // namespace ComPrivate
} // namespace ROSBridge
