///
/// JNetworkState.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 "NetworkState.hpp"

#include "JNetworkStateType.hpp"
#include "NetworkStateType.hpp"

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NetworkState by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NetworkState toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JNetworkStateType>("type");
      jni::local_ref<JNetworkStateType> type = this->getFieldValue(fieldType);
      static const auto fieldIsConnected = clazz->getField<jboolean>("isConnected");
      jboolean isConnected = this->getFieldValue(fieldIsConnected);
      static const auto fieldIsInternetReachable = clazz->getField<jboolean>("isInternetReachable");
      jboolean isInternetReachable = this->getFieldValue(fieldIsInternetReachable);
      return NetworkState(
        type->toCpp(),
        static_cast<bool>(isConnected),
        static_cast<bool>(isInternetReachable)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JNetworkState::javaobject> fromCpp(const NetworkState& value) {
      using JSignature = JNetworkState(jni::alias_ref<JNetworkStateType>, jboolean, jboolean);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JNetworkStateType::fromCpp(value.type),
        value.isConnected,
        value.isInternetReachable
      );
    }
  };

} // namespace margelo::nitro::one
