#ifndef AR3_HARDWARE__AR3_SYSTEM_HPP_
#define AR3_HARDWARE__AR3_SYSTEM_HPP_

#include <memory>
#include <string>
#include <vector>
#include <thread>

#include "hardware_interface/base_interface.hpp"
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_status_values.hpp"
#include "rclcpp/macros.hpp"
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/float32.hpp"

namespace ar3_hardware
{
class Ar3SystemHardware
: public hardware_interface::BaseInterface<hardware_interface::SystemInterface>
{
public:
  RCLCPP_SHARED_PTR_DEFINITIONS(Ar3SystemHardware)

  __attribute__((visibility("default")))
  hardware_interface::return_type configure(const hardware_interface::HardwareInfo & info) override;

  __attribute__((visibility("default")))
  std::vector<hardware_interface::StateInterface> export_state_interfaces() override;

  __attribute__((visibility("default")))
  std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;

  __attribute__((visibility("default")))
  hardware_interface::return_type start() override;

  __attribute__((visibility("default")))
  hardware_interface::return_type stop() override;

  __attribute__((visibility("default")))
  hardware_interface::return_type read() override;

  __attribute__((visibility("default")))
  hardware_interface::return_type write() override;

private:
  // Store the command for the simulated robot
  std::vector<double> hw_commands_;
  std::vector<double> hw_positions_;

  rclcpp::Node::SharedPtr nh_;
  rclcpp::executors::MultiThreadedExecutor::SharedPtr executor_;
  std::thread thread_executor_spin_;

  rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr j1_pub_;
  rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr j2_pub_;
  rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr j3_pub_;
  rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr j4_pub_;
  rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr j5_pub_;
  rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr j6_pub_;

  rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr s_j1;
  rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr s_j2;
  rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr s_j3;
  rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr s_j4;
  rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr s_j5;
  rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr s_j6;

  void update_j1_cb(std_msgs::msg::Float32::SharedPtr msg);
  void update_j2_cb(std_msgs::msg::Float32::SharedPtr msg);
  void update_j3_cb(std_msgs::msg::Float32::SharedPtr msg);
  void update_j4_cb(std_msgs::msg::Float32::SharedPtr msg);
  void update_j5_cb(std_msgs::msg::Float32::SharedPtr msg);
  void update_j6_cb(std_msgs::msg::Float32::SharedPtr msg);
};

}  // namespace ar3_hardware

#endif  // AR3_HARDWARE__AR3_SYSTEM_HPP_
