// GENERATED FILE - do not edit by hand
// Generated by src/scripts/gen_payload_converters.py
#pragma once

#include <yaml-cpp/yaml.h>
#include <string>
#include <vector>
#include <cstdint>
#include "interfaces/action/arm.hpp"
#include "interfaces/action/arm_space_control.hpp"
#include "interfaces/action/camera_take_photo.hpp"
#include "interfaces/action/hand_control.hpp"
#include "interfaces/action/leg_control.hpp"
#include "interfaces/action/move_home.hpp"
#include "interfaces/action/move_leg.hpp"
#include "interfaces/action/move_to_position.hpp"
#include "interfaces/action/move_waist.hpp"
#include "interfaces/action/move_wheel.hpp"
#include "interfaces/action/slam_mode.hpp"
#include "interfaces/action/vision_grasp_object.hpp"
#include "interfaces/srv/map_load.hpp"
#include "interfaces/srv/map_save.hpp"
#include "interfaces/srv/vision_object_recognition.hpp"


namespace brain {

template<typename T>
T from_yaml(const YAML::Node & n);

// VisionObjectRecognition::Request: camera_position
template<>
inline interfaces::srv::VisionObjectRecognition::Request from_yaml<interfaces::srv::VisionObjectRecognition::Request>(const YAML::Node & n)
{
  interfaces::srv::VisionObjectRecognition::Request r;
  if (n && n.IsMap()) {
    if (n["camera_position"]) r.camera_position = n["camera_position"].as<std::string>();
  }
  return r;
}

// MapLoad::Request: map_url
template<>
inline interfaces::srv::MapLoad::Request from_yaml<interfaces::srv::MapLoad::Request>(const YAML::Node & n)
{
  interfaces::srv::MapLoad::Request r;
  if (n && n.IsMap()) {
    if (n["map_url"]) r.map_url = n["map_url"].as<std::string>();
  }
  return r;
}

// MapSave::Request: map_url
template<>
inline interfaces::srv::MapSave::Request from_yaml<interfaces::srv::MapSave::Request>(const YAML::Node & n)
{
  interfaces::srv::MapSave::Request r;
  if (n && n.IsMap()) {
    if (n["map_url"]) r.map_url = n["map_url"].as<std::string>();
  }
  return r;
}

// Arm::Goal: body_id, data_type, data_length, command_id, frame_time_stamp, data_array
template<>
inline interfaces::action::Arm::Goal from_yaml<interfaces::action::Arm::Goal>(const YAML::Node & n)
{
  interfaces::action::Arm::Goal g;
  if (n && n.IsMap()) {
    if (n["body_id"]) g.body_id = n["body_id"].as<int8_t>();
    if (n["data_type"]) g.data_type = n["data_type"].as<int8_t>();
    if (n["data_length"]) g.data_length = n["data_length"].as<int16_t>();
    if (n["command_id"]) g.command_id = n["command_id"].as<int64_t>();
    if (n["frame_time_stamp"]) g.frame_time_stamp = n["frame_time_stamp"].as<int64_t>();
    if (n["data_array"]) {
      auto vec = n["data_array"].as<std::vector<double>>();
      g.data_array.assign(vec.begin(), vec.end());
    }
  if (!g.data_array.empty()) {
    using DL = decltype(g.data_length);
    g.data_length = static_cast<DL>(g.data_array.size());
  }
  }
  return g;
}

// CameraTakePhoto::Goal: mode, effort
template<>
inline interfaces::action::CameraTakePhoto::Goal from_yaml<interfaces::action::CameraTakePhoto::Goal>(const YAML::Node & n)
{
  interfaces::action::CameraTakePhoto::Goal g;
  if (n && n.IsMap()) {
    if (n["mode"]) g.mode = n["mode"].as<int32_t>();
    if (n["effort"]) g.effort = n["effort"].as<float>();
  }
  return g;
}

// HandControl::Goal: mode, effort
template<>
inline interfaces::action::HandControl::Goal from_yaml<interfaces::action::HandControl::Goal>(const YAML::Node & n)
{
  interfaces::action::HandControl::Goal g;
  if (n && n.IsMap()) {
    if (n["mode"]) g.mode = n["mode"].as<int32_t>();
    if (n["effort"]) g.effort = n["effort"].as<float>();
  }
  return g;
}

// MoveWaist::Goal: move_pitch_degree, move_yaw_degree
template<>
inline interfaces::action::MoveWaist::Goal from_yaml<interfaces::action::MoveWaist::Goal>(const YAML::Node & n)
{
  interfaces::action::MoveWaist::Goal g;
  if (n && n.IsMap()) {
    if (n["move_pitch_degree"]) g.move_pitch_degree = n["move_pitch_degree"].as<float>();
    if (n["move_yaw_degree"]) g.move_yaw_degree = n["move_yaw_degree"].as<float>();
  }
  return g;
}

// MoveLeg::Goal: move_up_distance
template<>
inline interfaces::action::MoveLeg::Goal from_yaml<interfaces::action::MoveLeg::Goal>(const YAML::Node & n)
{
  interfaces::action::MoveLeg::Goal g;
  if (n && n.IsMap()) {
    if (n["move_up_distance"]) g.move_up_distance = n["move_up_distance"].as<float>();
  }
  return g;
}

// MoveWheel::Goal: move_distance, move_angle
template<>
inline interfaces::action::MoveWheel::Goal from_yaml<interfaces::action::MoveWheel::Goal>(const YAML::Node & n)
{
  interfaces::action::MoveWheel::Goal g;
  if (n && n.IsMap()) {
    if (n["move_distance"]) g.move_distance = n["move_distance"].as<float>();
    if (n["move_angle"]) g.move_angle = n["move_angle"].as<float>();
  }
  return g;
}

// MoveHome::Goal: 
template<>
inline interfaces::action::MoveHome::Goal from_yaml<interfaces::action::MoveHome::Goal>(const YAML::Node & n)
{
  interfaces::action::MoveHome::Goal g;
  if (n && n.IsMap()) {
  }
  return g;
}

// MoveToPosition::Goal: target_x, target_y
template<>
inline interfaces::action::MoveToPosition::Goal from_yaml<interfaces::action::MoveToPosition::Goal>(const YAML::Node & n)
{
  interfaces::action::MoveToPosition::Goal g;
  if (n && n.IsMap()) {
    if (n["target_x"]) g.target_x = n["target_x"].as<float>();
    if (n["target_y"]) g.target_y = n["target_y"].as<float>();
  }
  return g;
}

// SlamMode::Goal: enable_mapping
template<>
inline interfaces::action::SlamMode::Goal from_yaml<interfaces::action::SlamMode::Goal>(const YAML::Node & n)
{
  interfaces::action::SlamMode::Goal g;
  if (n && n.IsMap()) {
    if (n["enable_mapping"]) g.enable_mapping = n["enable_mapping"].as<bool>();
  }
  return g;
}

// ArmSpaceControl::Goal: target
template<>
inline interfaces::action::ArmSpaceControl::Goal from_yaml<interfaces::action::ArmSpaceControl::Goal>(const YAML::Node & n)
{
  interfaces::action::ArmSpaceControl::Goal g;
  if (n && n.IsMap()) {
    // geometry_msgs::msg::PoseStamped
    if (n) {
      if (n["frame_id"]) g.target.header.frame_id = n["frame_id"].as<std::string>();
      if (n["stamp_sec"]) g.target.header.stamp.sec = n["stamp_sec"].as<int32_t>();
      if (n["stamp_nanosec"]) g.target.header.stamp.nanosec = n["stamp_nanosec"].as<uint32_t>();
      if (auto p = n["position"]) {
        if (p["x"]) g.target.pose.position.x = p["x"].as<double>();
        if (p["y"]) g.target.pose.position.y = p["y"].as<double>();
        if (p["z"]) g.target.pose.position.z = p["z"].as<double>();
      }
      if (auto q = n["orientation"]) {
        if (q["x"]) g.target.pose.orientation.x = q["x"].as<double>();
        if (q["y"]) g.target.pose.orientation.y = q["y"].as<double>();
        if (q["z"]) g.target.pose.orientation.z = q["z"].as<double>();
        if (q["w"]) g.target.pose.orientation.w = q["w"].as<double>();
      }
    }
  }
  return g;
}

// LegControl::Goal: target
template<>
inline interfaces::action::LegControl::Goal from_yaml<interfaces::action::LegControl::Goal>(const YAML::Node & n)
{
  interfaces::action::LegControl::Goal g;
  if (n && n.IsMap()) {
    // geometry_msgs::msg::TwistStamped
    if (n) {
      if (n["frame_id"]) g.target.header.frame_id = n["frame_id"].as<std::string>();
      if (n["stamp_sec"]) g.target.header.stamp.sec = n["stamp_sec"].as<int32_t>();
      if (n["stamp_nanosec"]) g.target.header.stamp.nanosec = n["stamp_nanosec"].as<uint32_t>();
      if (auto lin = n["linear"]) {
        if (lin["x"]) g.target.twist.linear.x = lin["x"].as<double>();
        if (lin["y"]) g.target.twist.linear.y = lin["y"].as<double>();
        if (lin["z"]) g.target.twist.linear.z = lin["z"].as<double>();
      }
      if (auto ang = n["angular"]) {
        if (ang["x"]) g.target.twist.angular.x = ang["x"].as<double>();
        if (ang["y"]) g.target.twist.angular.y = ang["y"].as<double>();
        if (ang["z"]) g.target.twist.angular.z = ang["z"].as<double>();
      }
    }
  }
  return g;
}

// VisionGraspObject::Goal: object_id
template<>
inline interfaces::action::VisionGraspObject::Goal from_yaml<interfaces::action::VisionGraspObject::Goal>(const YAML::Node & n)
{
  interfaces::action::VisionGraspObject::Goal g;
  if (n && n.IsMap()) {
    if (n["object_id"]) g.object_id = n["object_id"].as<std::string>();
  }
  return g;
}

} // namespace brain
