#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 {

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


    Server() = delete;
    Server(CasePacker &casePacker, 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;
    CasePacker         &_casePacker;
    ServiceMap         _serviceMap;
    std::shared_ptr<std::atomic_bool> _stopped;
};
} // namespace ComPrivate
} // namespace ROSBridge
