///
/// JPTSessionResult.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 "PTSessionResult.hpp"

#include "JPTSessionStatus.hpp"
#include "PTSessionStatus.hpp"
#include <optional>

namespace margelo::nitro::espprovtoolkit {

  using namespace facebook;

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

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

} // namespace margelo::nitro::espprovtoolkit
