///
/// JHapticParameters.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 "HapticParameters.hpp"

#include <optional>

namespace margelo::nitro::haptic {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct HapticParameters by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    HapticParameters toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldIntensity = clazz->getField<jni::JDouble>("intensity");
      jni::local_ref<jni::JDouble> intensity = this->getFieldValue(fieldIntensity);
      static const auto fieldSharpness = clazz->getField<jni::JDouble>("sharpness");
      jni::local_ref<jni::JDouble> sharpness = this->getFieldValue(fieldSharpness);
      return HapticParameters(
        intensity != nullptr ? std::make_optional(intensity->value()) : std::nullopt,
        sharpness != nullptr ? std::make_optional(sharpness->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<JHapticParameters::javaobject> fromCpp(const HapticParameters& value) {
      using JSignature = JHapticParameters(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,
        value.intensity.has_value() ? jni::JDouble::valueOf(value.intensity.value()) : nullptr,
        value.sharpness.has_value() ? jni::JDouble::valueOf(value.sharpness.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::haptic
