///
/// JScanOptions.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 "ScanOptions.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 "ScanOptions" and the the Kotlin data class "ScanOptions".
   */
  struct JScanOptions final: public jni::JavaClass<JScanOptions> {
  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/munimbluetooth/ScanOptions;";

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

} // namespace margelo::nitro::munimbluetooth
