#pragma once

#include <QJsonObject>

#include <QDebug>
#include <QString>

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 {

QString 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(""), _progress(0) {}
  LabeledProgress(double progress, QString id) : _id(id), _progress(progress) {}

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

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

protected:
  QString _id;
  double _progress;
};

template <class LabeledProgressType>
bool toJson(const LabeledProgressType &lp, QJsonObject &value) {
  value[idKey] = lp.id();
  value[progressKey] = lp.progress();
  return true;
}

template <class ProgressType>
bool fromJson(const QJsonObject &value, ProgressType &p) {
  if (!value.contains(progressKey) || !value[progressKey].isDouble()) {
    return false;
  }

  if (!value.contains(idKey) || !value[idKey].isString()) {
    return false;
  }

  p.setId(value[idKey].toString());
  p.setProgress(value[progressKey].toDouble());

  return true;
}

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