///
/// JAudioRemoteCommandEvent.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 "AudioRemoteCommandEvent.hpp"

#include "AudioRemoteCommandType.hpp"
#include "JAudioRemoteCommandType.hpp"
#include <optional>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct AudioRemoteCommandEvent by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    AudioRemoteCommandEvent toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JAudioRemoteCommandType>("type");
      jni::local_ref<JAudioRemoteCommandType> type = this->getFieldValue(fieldType);
      static const auto fieldPositionMs = clazz->getField<jni::JDouble>("positionMs");
      jni::local_ref<jni::JDouble> positionMs = this->getFieldValue(fieldPositionMs);
      return AudioRemoteCommandEvent(
        type->toCpp(),
        positionMs != nullptr ? std::make_optional(positionMs->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<JAudioRemoteCommandEvent::javaobject> fromCpp(const AudioRemoteCommandEvent& value) {
      using JSignature = JAudioRemoteCommandEvent(jni::alias_ref<JAudioRemoteCommandType>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JAudioRemoteCommandType::fromCpp(value.type),
        value.positionMs.has_value() ? jni::JDouble::valueOf(value.positionMs.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
