///
/// JPTResult.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 "PTResult.hpp"

#include <optional>

namespace margelo::nitro::espprovtoolkit {

  using namespace facebook;

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

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

} // namespace margelo::nitro::espprovtoolkit
