///
/// JPTDeviceResult.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 "PTDeviceResult.hpp"

#include "JPTDevice.hpp"
#include "JPTSecurity.hpp"
#include "JPTTransport.hpp"
#include "PTDevice.hpp"
#include "PTSecurity.hpp"
#include "PTTransport.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::espprovtoolkit {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct PTDeviceResult by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    PTDeviceResult toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldSuccess = clazz->getField<jboolean>("success");
      jboolean success = this->getFieldValue(fieldSuccess);
      static const auto fieldResult = clazz->getField<JPTDevice>("result");
      jni::local_ref<JPTDevice> result = this->getFieldValue(fieldResult);
      return PTDeviceResult(
        static_cast<bool>(success),
        result != nullptr ? std::make_optional(result->toCpp()) : 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<JPTDeviceResult::javaobject> fromCpp(const PTDeviceResult& value) {
      using JSignature = JPTDeviceResult(jboolean, jni::alias_ref<JPTDevice>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.success,
        value.result.has_value() ? JPTDevice::fromCpp(value.result.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::espprovtoolkit
