///
/// JMultipeerPeer.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 "MultipeerPeer.hpp"

#include "JMultipeerDiscoveryInfoEntry.hpp"
#include "JMultipeerPeerState.hpp"
#include "MultipeerDiscoveryInfoEntry.hpp"
#include "MultipeerPeerState.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::munimbluetooth {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MultipeerPeer by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MultipeerPeer 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 fieldDisplayName = clazz->getField<jni::JString>("displayName");
      jni::local_ref<jni::JString> displayName = this->getFieldValue(fieldDisplayName);
      static const auto fieldState = clazz->getField<JMultipeerPeerState>("state");
      jni::local_ref<JMultipeerPeerState> state = this->getFieldValue(fieldState);
      static const auto fieldDiscoveryInfo = clazz->getField<jni::JArrayClass<JMultipeerDiscoveryInfoEntry>>("discoveryInfo");
      jni::local_ref<jni::JArrayClass<JMultipeerDiscoveryInfoEntry>> discoveryInfo = this->getFieldValue(fieldDiscoveryInfo);
      return MultipeerPeer(
        id->toStdString(),
        displayName->toStdString(),
        state->toCpp(),
        discoveryInfo != nullptr ? std::make_optional([&](auto&& __input) {
          size_t __size = __input->size();
          std::vector<MultipeerDiscoveryInfoEntry> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = __input->getElement(__i);
            __vector.push_back(__element->toCpp());
          }
          return __vector;
        }(discoveryInfo)) : 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<JMultipeerPeer::javaobject> fromCpp(const MultipeerPeer& value) {
      using JSignature = JMultipeerPeer(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JMultipeerPeerState>, jni::alias_ref<jni::JArrayClass<JMultipeerDiscoveryInfoEntry>>);
      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.displayName),
        JMultipeerPeerState::fromCpp(value.state),
        value.discoveryInfo.has_value() ? [&](auto&& __input) {
          size_t __size = __input.size();
          jni::local_ref<jni::JArrayClass<JMultipeerDiscoveryInfoEntry>> __array = jni::JArrayClass<JMultipeerDiscoveryInfoEntry>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = __input[__i];
            auto __elementJni = JMultipeerDiscoveryInfoEntry::fromCpp(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }(value.discoveryInfo.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::munimbluetooth
