#pragma once

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

#include <vector>


namespace ros_bridge {
//! @brief Namespace containing classes and methodes ros message generation.
namespace messages {
//! @brief Namespace containing classes and methodes for geometry_msgs generation.
namespace nemo_msgs {
//! @brief Namespace containing methodes for geometry_msgs/Point32 message generation.
namespace progress {


std::string messageType();

//! @brief C++ representation of nemo_msgs/Progress message
template <class IntType = long, template <class, class...> class ContainterType = std::vector>
class GenericProgress{
public:
    GenericProgress() {}
    GenericProgress(const ContainterType<IntType> &progress) : _progress(progress){}
    GenericProgress(const GenericProgress &p) : _progress(p.progress()){}

    virtual const ContainterType<IntType> &progress(void) const {return _progress;}
    virtual       ContainterType<IntType> &progress(void)       {return _progress;}

protected:
    ContainterType<IntType> _progress;
};
typedef GenericProgress<> Progress;


template <class ProgressType>
bool toJson(const ProgressType &p, rapidjson::Value &value, rapidjson::Document::AllocatorType &allocator)
{
    rapidjson::Value jProgress(rapidjson::kArrayType);
    for(unsigned long i=0; i < std::uint64_t(p.progress().size()); ++i){
        jProgress.PushBack(rapidjson::Value().SetInt(std::int32_t(p.progress()[i])), allocator);
    }
    value.AddMember("progress", jProgress, allocator);
    return true;
}

template <class ProgressType>
bool fromJson(const rapidjson::Value &value, ProgressType &p)
{
    if (!value.HasMember("progress") || !value["progress"].IsArray()){
        assert(false);
        return false;
    }

    const auto& jsonProgress = value["progress"];
    unsigned long sz = jsonProgress.Size();
    p.progress().clear();
    p.progress().reserve(sz);
    for (unsigned long i=0; i < sz; ++i)
        p.progress().push_back(std::int32_t(jsonProgress[i].GetInt()));
    return true;
}

} // namespace progress
} // namespace nemo_msgs
} // namespace messages
} // namespace ros_bridge
