///
/// JGATTDescriptor.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 "GATTDescriptor.hpp"

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

namespace margelo::nitro::munimbluetooth {

  using namespace facebook;

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

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

} // namespace margelo::nitro::munimbluetooth
