#pragma once

#include <QJsonObject>

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/GeoPoint message
//! generation.
namespace heartbeat {

std::string messageType();

//! @brief C++ representation of nemo_msgs/Heartbeat message
class Heartbeat {
public:
  Heartbeat() : _status(0) {}
  Heartbeat(int status) : _status(status) {}
  Heartbeat(const Heartbeat &heartbeat) : _status(heartbeat.status()) {}

  bool operator==(const Heartbeat &hb) { return hb._status == this->_status; }
  bool operator!=(const Heartbeat &hb) { return !operator==(hb); }

  virtual int status(void) const { return _status; }
  virtual void setStatus(int status) { _status = status; }

protected:
  int _status;
};

template <class HeartbeatType>
bool toJson(const HeartbeatType &heartbeat, QJsonObject &value) {
  value["status"] = heartbeat.status();
  return true;
}

template <class HeartbeatType>
bool fromJson(const QJsonObject &value, HeartbeatType &heartbeat) {
  if (!value.contains("status") || !value["status"].isDouble()) {
    return false;
  }

  heartbeat.setStatus(value["status"].toInt());
  return true;
}

} // namespace heartbeat
} // namespace nemo_msgs
} // namespace messages
} // namespace ros_bridge
