///
/// JNativeTriggerInput.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 "NativeTriggerInput.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

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

} // namespace margelo::nitro::one
