///
/// JPTStringResult.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 "PTStringResult.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::espprovtoolkit {

  using namespace facebook;

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

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

} // namespace margelo::nitro::espprovtoolkit
