///
/// JBackgroundSessionOptions.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 "BackgroundSessionOptions.hpp"

#include "JScanMode.hpp"
#include "ScanMode.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::munimbluetooth {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct BackgroundSessionOptions by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    BackgroundSessionOptions toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldServiceUUIDs = clazz->getField<jni::JArrayClass<jni::JString>>("serviceUUIDs");
      jni::local_ref<jni::JArrayClass<jni::JString>> serviceUUIDs = this->getFieldValue(fieldServiceUUIDs);
      static const auto fieldLocalName = clazz->getField<jni::JString>("localName");
      jni::local_ref<jni::JString> localName = this->getFieldValue(fieldLocalName);
      static const auto fieldAllowDuplicates = clazz->getField<jni::JBoolean>("allowDuplicates");
      jni::local_ref<jni::JBoolean> allowDuplicates = this->getFieldValue(fieldAllowDuplicates);
      static const auto fieldScanMode = clazz->getField<JScanMode>("scanMode");
      jni::local_ref<JScanMode> scanMode = this->getFieldValue(fieldScanMode);
      static const auto fieldAndroidNotificationChannelId = clazz->getField<jni::JString>("androidNotificationChannelId");
      jni::local_ref<jni::JString> androidNotificationChannelId = this->getFieldValue(fieldAndroidNotificationChannelId);
      static const auto fieldAndroidNotificationChannelName = clazz->getField<jni::JString>("androidNotificationChannelName");
      jni::local_ref<jni::JString> androidNotificationChannelName = this->getFieldValue(fieldAndroidNotificationChannelName);
      static const auto fieldAndroidNotificationTitle = clazz->getField<jni::JString>("androidNotificationTitle");
      jni::local_ref<jni::JString> androidNotificationTitle = this->getFieldValue(fieldAndroidNotificationTitle);
      static const auto fieldAndroidNotificationText = clazz->getField<jni::JString>("androidNotificationText");
      jni::local_ref<jni::JString> androidNotificationText = this->getFieldValue(fieldAndroidNotificationText);
      return BackgroundSessionOptions(
        [&](auto&& __input) {
          size_t __size = __input->size();
          std::vector<std::string> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = __input->getElement(__i);
            __vector.push_back(__element->toStdString());
          }
          return __vector;
        }(serviceUUIDs),
        localName != nullptr ? std::make_optional(localName->toStdString()) : std::nullopt,
        allowDuplicates != nullptr ? std::make_optional(static_cast<bool>(allowDuplicates->value())) : std::nullopt,
        scanMode != nullptr ? std::make_optional(scanMode->toCpp()) : std::nullopt,
        androidNotificationChannelId != nullptr ? std::make_optional(androidNotificationChannelId->toStdString()) : std::nullopt,
        androidNotificationChannelName != nullptr ? std::make_optional(androidNotificationChannelName->toStdString()) : std::nullopt,
        androidNotificationTitle != nullptr ? std::make_optional(androidNotificationTitle->toStdString()) : std::nullopt,
        androidNotificationText != nullptr ? std::make_optional(androidNotificationText->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<JBackgroundSessionOptions::javaobject> fromCpp(const BackgroundSessionOptions& value) {
      using JSignature = JBackgroundSessionOptions(jni::alias_ref<jni::JArrayClass<jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JScanMode>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        [&](auto&& __input) {
          size_t __size = __input.size();
          jni::local_ref<jni::JArrayClass<jni::JString>> __array = jni::JArrayClass<jni::JString>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = __input[__i];
            auto __elementJni = jni::make_jstring(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }(value.serviceUUIDs),
        value.localName.has_value() ? jni::make_jstring(value.localName.value()) : nullptr,
        value.allowDuplicates.has_value() ? jni::JBoolean::valueOf(value.allowDuplicates.value()) : nullptr,
        value.scanMode.has_value() ? JScanMode::fromCpp(value.scanMode.value()) : nullptr,
        value.androidNotificationChannelId.has_value() ? jni::make_jstring(value.androidNotificationChannelId.value()) : nullptr,
        value.androidNotificationChannelName.has_value() ? jni::make_jstring(value.androidNotificationChannelName.value()) : nullptr,
        value.androidNotificationTitle.has_value() ? jni::make_jstring(value.androidNotificationTitle.value()) : nullptr,
        value.androidNotificationText.has_value() ? jni::make_jstring(value.androidNotificationText.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::munimbluetooth
