///
/// JNitroVerifyPurchaseWithProviderError.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 "NitroVerifyPurchaseWithProviderError.hpp"

#include "JVariant_NullType_String.hpp"
#include <NitroModules/JNull.hpp>
#include <NitroModules/Null.hpp>
#include <optional>
#include <string>
#include <variant>

namespace margelo::nitro::iap {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NitroVerifyPurchaseWithProviderError by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NitroVerifyPurchaseWithProviderError toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldCode = clazz->getField<JVariant_NullType_String>("code");
      jni::local_ref<JVariant_NullType_String> code = this->getFieldValue(fieldCode);
      static const auto fieldMessage = clazz->getField<jni::JString>("message");
      jni::local_ref<jni::JString> message = this->getFieldValue(fieldMessage);
      return NitroVerifyPurchaseWithProviderError(
        code != nullptr ? std::make_optional(code->toCpp()) : std::nullopt,
        message->toStdString()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JNitroVerifyPurchaseWithProviderError::javaobject> fromCpp(const NitroVerifyPurchaseWithProviderError& value) {
      using JSignature = JNitroVerifyPurchaseWithProviderError(jni::alias_ref<JVariant_NullType_String>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.code.has_value() ? JVariant_NullType_String::fromCpp(value.code.value()) : nullptr,
        jni::make_jstring(value.message)
      );
    }
  };

} // namespace margelo::nitro::iap
