///
/// JNetConfig.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 "NetConfig.hpp"

#include <optional>

namespace margelo::nitro::net {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NetConfig by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NetConfig toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldWorkerThreads = clazz->getField<jni::JDouble>("workerThreads");
      jni::local_ref<jni::JDouble> workerThreads = this->getFieldValue(fieldWorkerThreads);
      static const auto fieldDebug = clazz->getField<jni::JBoolean>("debug");
      jni::local_ref<jni::JBoolean> debug = this->getFieldValue(fieldDebug);
      return NetConfig(
        workerThreads != nullptr ? std::make_optional(workerThreads->value()) : std::nullopt,
        debug != nullptr ? std::make_optional(static_cast<bool>(debug->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<JNetConfig::javaobject> fromCpp(const NetConfig& value) {
      using JSignature = JNetConfig(jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.workerThreads.has_value() ? jni::JDouble::valueOf(value.workerThreads.value()) : nullptr,
        value.debug.has_value() ? jni::JBoolean::valueOf(value.debug.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::net
