#pragma once

#include "ros_bridge/include/com_private.h"
#include "ros_bridge/include/RosBridgeClient.h"

#include <unordered_map>

namespace ros_bridge {
namespace com_private {


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

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

    TopicSubscriber() = delete;
    TopicSubscriber(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:
    RosbridgeWsClient   &_rbc;
    TopicMap            _topicMap;
    std::shared_ptr<std::atomic_bool>   _stopped;
};

} // namespace ComPrivate
} // namespace ROSBridge
