///
/// JNativeChannelInput.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 "NativeChannelInput.hpp"

#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NativeChannelInput by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NativeChannelInput toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldName = clazz->getField<jni::JString>("name");
      jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
      static const auto fieldImportance = clazz->getField<double>("importance");
      double importance = this->getFieldValue(fieldImportance);
      static const auto fieldDescription = clazz->getField<jni::JString>("description");
      jni::local_ref<jni::JString> description = this->getFieldValue(fieldDescription);
      static const auto fieldSound = clazz->getField<jni::JBoolean>("sound");
      jni::local_ref<jni::JBoolean> sound = this->getFieldValue(fieldSound);
      static const auto fieldVibrationPattern = clazz->getField<jni::JArrayDouble>("vibrationPattern");
      jni::local_ref<jni::JArrayDouble> vibrationPattern = this->getFieldValue(fieldVibrationPattern);
      static const auto fieldShowBadge = clazz->getField<jni::JBoolean>("showBadge");
      jni::local_ref<jni::JBoolean> showBadge = this->getFieldValue(fieldShowBadge);
      return NativeChannelInput(
        name->toStdString(),
        importance,
        description != nullptr ? std::make_optional(description->toStdString()) : std::nullopt,
        sound != nullptr ? std::make_optional(static_cast<bool>(sound->value())) : std::nullopt,
        vibrationPattern != nullptr ? std::make_optional([&]() {
          size_t __size = vibrationPattern->size();
          std::vector<double> __vector(__size);
          vibrationPattern->getRegion(0, __size, __vector.data());
          return __vector;
        }()) : std::nullopt,
        showBadge != nullptr ? std::make_optional(static_cast<bool>(showBadge->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<JNativeChannelInput::javaobject> fromCpp(const NativeChannelInput& value) {
      using JSignature = JNativeChannelInput(jni::alias_ref<jni::JString>, double, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JArrayDouble>, jni::alias_ref<jni::JBoolean>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.name),
        value.importance,
        value.description.has_value() ? jni::make_jstring(value.description.value()) : nullptr,
        value.sound.has_value() ? jni::JBoolean::valueOf(value.sound.value()) : nullptr,
        value.vibrationPattern.has_value() ? [&]() {
          size_t __size = value.vibrationPattern.value().size();
          jni::local_ref<jni::JArrayDouble> __array = jni::JArrayDouble::newArray(__size);
          __array->setRegion(0, __size, value.vibrationPattern.value().data());
          return __array;
        }() : nullptr,
        value.showBadge.has_value() ? jni::JBoolean::valueOf(value.showBadge.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
