#pragma once

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

#include <unordered_map>

namespace ros_bridge {
namespace com_private {

class Server
{
    typedef std::unordered_map<std::string, std::string>  ServiceMap;
public:
    typedef std::function<JsonDocUPtr(JsonDocUPtr)> CallbackType;


    Server() = delete;
    Server(RosbridgeWsClient &rbc);
    ~Server();

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

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

    void advertiseService(const std::string& service,
                          const std::string& type,
                          const CallbackType& userCallback);

private:

    RosbridgeWsClient  &_rbc;
    ServiceMap         _serviceMap;
    std::shared_ptr<std::atomic_bool> _stopped;
};
} // namespace ComPrivate
} // namespace ROSBridge
