///
/// JNativeChannel.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 "NativeChannel.hpp"

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

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NativeChannel by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NativeChannel toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldId = clazz->getField<jni::JString>("id");
      jni::local_ref<jni::JString> id = this->getFieldValue(fieldId);
      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<jboolean>("sound");
      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<jboolean>("showBadge");
      jboolean showBadge = this->getFieldValue(fieldShowBadge);
      return NativeChannel(
        id->toStdString(),
        name->toStdString(),
        importance,
        description != nullptr ? std::make_optional(description->toStdString()) : std::nullopt,
        static_cast<bool>(sound),
        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,
        static_cast<bool>(showBadge)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JNativeChannel::javaobject> fromCpp(const NativeChannel& value) {
      using JSignature = JNativeChannel(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, double, jni::alias_ref<jni::JString>, jboolean, jni::alias_ref<jni::JArrayDouble>, jboolean);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.id),
        jni::make_jstring(value.name),
        value.importance,
        value.description.has_value() ? jni::make_jstring(value.description.value()) : nullptr,
        value.sound,
        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
      );
    }
  };

} // namespace margelo::nitro::one
