///
/// JNitroPurchaseResult.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 "NitroPurchaseResult.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::iap {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NitroPurchaseResult by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NitroPurchaseResult toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldResponseCode = clazz->getField<double>("responseCode");
      double responseCode = this->getFieldValue(fieldResponseCode);
      static const auto fieldDebugMessage = clazz->getField<jni::JString>("debugMessage");
      jni::local_ref<jni::JString> debugMessage = this->getFieldValue(fieldDebugMessage);
      static const auto fieldCode = clazz->getField<jni::JString>("code");
      jni::local_ref<jni::JString> code = this->getFieldValue(fieldCode);
      static const auto fieldMessage = clazz->getField<jni::JString>("message");
      jni::local_ref<jni::JString> message = this->getFieldValue(fieldMessage);
      static const auto fieldPurchaseToken = clazz->getField<jni::JString>("purchaseToken");
      jni::local_ref<jni::JString> purchaseToken = this->getFieldValue(fieldPurchaseToken);
      return NitroPurchaseResult(
        responseCode,
        debugMessage != nullptr ? std::make_optional(debugMessage->toStdString()) : std::nullopt,
        code->toStdString(),
        message->toStdString(),
        purchaseToken != nullptr ? std::make_optional(purchaseToken->toStdString()) : 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<JNitroPurchaseResult::javaobject> fromCpp(const NitroPurchaseResult& value) {
      using JSignature = JNitroPurchaseResult(double, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.responseCode,
        value.debugMessage.has_value() ? jni::make_jstring(value.debugMessage.value()) : nullptr,
        jni::make_jstring(value.code),
        jni::make_jstring(value.message),
        value.purchaseToken.has_value() ? jni::make_jstring(value.purchaseToken.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::iap
