///
/// JRemoteCommandEvent.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include "RemoteCommandEvent.hpp"

#include "JRemoteCommand.hpp"
#include "RemoteCommand.hpp"
#include <optional>

namespace margelo::nitro::aviation {

  using namespace facebook;

  /**
   * The C++ JNI bridge between the C++ struct "RemoteCommandEvent" and the the Kotlin data class "RemoteCommandEvent".
   */
  struct JRemoteCommandEvent final: public jni::JavaClass<JRemoteCommandEvent> {
  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/aviation/RemoteCommandEvent;";

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct RemoteCommandEvent by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    RemoteCommandEvent toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldCommand = clazz->getField<JRemoteCommand>("command");
      jni::local_ref<JRemoteCommand> command = this->getFieldValue(fieldCommand);
      static const auto fieldPositionMs = clazz->getField<jni::JDouble>("positionMs");
      jni::local_ref<jni::JDouble> positionMs = this->getFieldValue(fieldPositionMs);
      static const auto fieldIntervalMs = clazz->getField<jni::JDouble>("intervalMs");
      jni::local_ref<jni::JDouble> intervalMs = this->getFieldValue(fieldIntervalMs);
      return RemoteCommandEvent(
        command->toCpp(),
        positionMs != nullptr ? std::make_optional(positionMs->value()) : std::nullopt,
        intervalMs != nullptr ? std::make_optional(intervalMs->value()) : std::nullopt
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JRemoteCommandEvent::javaobject> fromCpp(const RemoteCommandEvent& value) {
      using JSignature = JRemoteCommandEvent(jni::alias_ref<JRemoteCommand>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JRemoteCommand::fromCpp(value.command),
        value.positionMs.has_value() ? jni::JDouble::valueOf(value.positionMs.value()) : nullptr,
        value.intervalMs.has_value() ? jni::JDouble::valueOf(value.intervalMs.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::aviation
