///
/// JPTWifiEntry.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 "PTWifiEntry.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::espprovtoolkit {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct PTWifiEntry by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    PTWifiEntry toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldSsid = clazz->getField<jni::JString>("ssid");
      jni::local_ref<jni::JString> ssid = this->getFieldValue(fieldSsid);
      static const auto fieldRssi = clazz->getField<double>("rssi");
      double rssi = this->getFieldValue(fieldRssi);
      static const auto fieldAuth = clazz->getField<double>("auth");
      double auth = this->getFieldValue(fieldAuth);
      static const auto fieldBssid = clazz->getField<jni::JString>("bssid");
      jni::local_ref<jni::JString> bssid = this->getFieldValue(fieldBssid);
      static const auto fieldChannel = clazz->getField<jni::JDouble>("channel");
      jni::local_ref<jni::JDouble> channel = this->getFieldValue(fieldChannel);
      return PTWifiEntry(
        ssid->toStdString(),
        rssi,
        auth,
        bssid != nullptr ? std::make_optional(bssid->toStdString()) : std::nullopt,
        channel != nullptr ? std::make_optional(channel->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<JPTWifiEntry::javaobject> fromCpp(const PTWifiEntry& value) {
      using JSignature = JPTWifiEntry(jni::alias_ref<jni::JString>, double, double, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.ssid),
        value.rssi,
        value.auth,
        value.bssid.has_value() ? jni::make_jstring(value.bssid.value()) : nullptr,
        value.channel.has_value() ? jni::JDouble::valueOf(value.channel.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::espprovtoolkit
