///
/// JExternalPurchaseLinkResultIOS.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 "ExternalPurchaseLinkResultIOS.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 "ExternalPurchaseLinkResultIOS" and the the Kotlin data class "ExternalPurchaseLinkResultIOS".
   */
  struct JExternalPurchaseLinkResultIOS final: public jni::JavaClass<JExternalPurchaseLinkResultIOS> {
  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/ExternalPurchaseLinkResultIOS;";

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ExternalPurchaseLinkResultIOS by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ExternalPurchaseLinkResultIOS toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldError = clazz->getField<JVariant_NullType_String>("error");
      jni::local_ref<JVariant_NullType_String> error = this->getFieldValue(fieldError);
      static const auto fieldSuccess = clazz->getField<jboolean>("success");
      jboolean success = this->getFieldValue(fieldSuccess);
      return ExternalPurchaseLinkResultIOS(
        error != nullptr ? std::make_optional(error->toCpp()) : std::nullopt,
        static_cast<bool>(success)
      );
    }

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

} // namespace margelo::nitro::iap
