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

std::string messageType();

namespace {
const char *progressKey = "progress";
const char *idKey = "id";
} // namespace

//! @brief C++ representation of nemo_msgs/labeled_progress message
class LabeledProgress {
public:
  LabeledProgress() : _id(0), _progress(0) {}
  LabeledProgress(double progress, long id) : _id(id), _progress(progress) {}

  long id() const { return _id; }
  void setId(long id) { _id = id; }

  double progress() const { return _progress; }
  void setProgress(double progress) { _progress = progress; }

protected:
  long _id;
  double _progress;
};

template <class LabeledProgressType>
bool toJson(const LabeledProgressType &lp, rapidjson::Value &value,
            rapidjson::Document::AllocatorType &allocator) {
  value.AddMember(idKey, lp.id(), allocator);
  value.AddMember(progressKey, lp.progress(), allocator);
  return true;
}

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

  if (!value.HasMember(idKey) || !value[idKey].IsInt64()) {
    return false;
  }

  p.setId(value[idKey].GetInt64());
  p.setProgress(value[progressKey].GetDouble());

  return true;
}

} // namespace labeled_progress
} // namespace nemo_msgs
} // namespace messages
} // namespace ros_bridge
