///
/// JNativeTrigger.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 "NativeTrigger.hpp"

#include "JNativeTriggerType.hpp"
#include "NativeTriggerType.hpp"
#include <optional>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NativeTrigger by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NativeTrigger toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JNativeTriggerType>("type");
      jni::local_ref<JNativeTriggerType> type = this->getFieldValue(fieldType);
      static const auto fieldSeconds = clazz->getField<jni::JDouble>("seconds");
      jni::local_ref<jni::JDouble> seconds = this->getFieldValue(fieldSeconds);
      static const auto fieldRepeats = clazz->getField<jni::JBoolean>("repeats");
      jni::local_ref<jni::JBoolean> repeats = this->getFieldValue(fieldRepeats);
      static const auto fieldDate = clazz->getField<jni::JDouble>("date");
      jni::local_ref<jni::JDouble> date = this->getFieldValue(fieldDate);
      return NativeTrigger(
        type->toCpp(),
        seconds != nullptr ? std::make_optional(seconds->value()) : std::nullopt,
        repeats != nullptr ? std::make_optional(static_cast<bool>(repeats->value())) : std::nullopt,
        date != nullptr ? std::make_optional(date->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<JNativeTrigger::javaobject> fromCpp(const NativeTrigger& value) {
      using JSignature = JNativeTrigger(jni::alias_ref<JNativeTriggerType>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JNativeTriggerType::fromCpp(value.type),
        value.seconds.has_value() ? jni::JDouble::valueOf(value.seconds.value()) : nullptr,
        value.repeats.has_value() ? jni::JBoolean::valueOf(value.repeats.value()) : nullptr,
        value.date.has_value() ? jni::JDouble::valueOf(value.date.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
