///
/// JHapticEvent.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 "HapticEvent.hpp"

#include "HapticEventType.hpp"
#include "HapticParameters.hpp"
#include "JHapticEventType.hpp"
#include "JHapticParameters.hpp"
#include <optional>

namespace margelo::nitro::haptic {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct HapticEvent by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    HapticEvent toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldEventType = clazz->getField<JHapticEventType>("eventType");
      jni::local_ref<JHapticEventType> eventType = this->getFieldValue(fieldEventType);
      static const auto fieldTime = clazz->getField<double>("time");
      double time = this->getFieldValue(fieldTime);
      static const auto fieldEventDuration = clazz->getField<jni::JDouble>("eventDuration");
      jni::local_ref<jni::JDouble> eventDuration = this->getFieldValue(fieldEventDuration);
      static const auto fieldParameters = clazz->getField<JHapticParameters>("parameters");
      jni::local_ref<JHapticParameters> parameters = this->getFieldValue(fieldParameters);
      return HapticEvent(
        eventType->toCpp(),
        time,
        eventDuration != nullptr ? std::make_optional(eventDuration->value()) : std::nullopt,
        parameters != nullptr ? std::make_optional(parameters->toCpp()) : 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<JHapticEvent::javaobject> fromCpp(const HapticEvent& value) {
      using JSignature = JHapticEvent(jni::alias_ref<JHapticEventType>, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<JHapticParameters>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JHapticEventType::fromCpp(value.eventType),
        value.time,
        value.eventDuration.has_value() ? jni::JDouble::valueOf(value.eventDuration.value()) : nullptr,
        value.parameters.has_value() ? JHapticParameters::fromCpp(value.parameters.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::haptic
