///
/// JPTWifiScanResult.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 "PTWifiScanResult.hpp"

#include "JPTWifiEntry.hpp"
#include "PTWifiEntry.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::espprovtoolkit {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct PTWifiScanResult by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    PTWifiScanResult toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldSuccess = clazz->getField<jboolean>("success");
      jboolean success = this->getFieldValue(fieldSuccess);
      static const auto fieldNetworks = clazz->getField<jni::JArrayClass<JPTWifiEntry>>("networks");
      jni::local_ref<jni::JArrayClass<JPTWifiEntry>> networks = this->getFieldValue(fieldNetworks);
      static const auto fieldError = clazz->getField<jni::JDouble>("error");
      jni::local_ref<jni::JDouble> error = this->getFieldValue(fieldError);
      return PTWifiScanResult(
        static_cast<bool>(success),
        networks != nullptr ? std::make_optional([&](auto&& __input) {
          size_t __size = __input->size();
          std::vector<PTWifiEntry> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = __input->getElement(__i);
            __vector.push_back(__element->toCpp());
          }
          return __vector;
        }(networks)) : std::nullopt,
        error != nullptr ? std::make_optional(error->value()) : 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<JPTWifiScanResult::javaobject> fromCpp(const PTWifiScanResult& value) {
      using JSignature = JPTWifiScanResult(jboolean, jni::alias_ref<jni::JArrayClass<JPTWifiEntry>>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.success,
        value.networks.has_value() ? [&](auto&& __input) {
          size_t __size = __input.size();
          jni::local_ref<jni::JArrayClass<JPTWifiEntry>> __array = jni::JArrayClass<JPTWifiEntry>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = __input[__i];
            auto __elementJni = JPTWifiEntry::fromCpp(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }(value.networks.value()) : nullptr,
        value.error.has_value() ? jni::JDouble::valueOf(value.error.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::espprovtoolkit
