///
/// JNitroVerifyPurchaseWithProviderResult.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 "NitroVerifyPurchaseWithProviderResult.hpp"

#include "IapStore.hpp"
#include "IapkitPurchaseState.hpp"
#include "JIapStore.hpp"
#include "JIapkitPurchaseState.hpp"
#include "JNitroVerifyPurchaseWithIapkitResult.hpp"
#include "JNitroVerifyPurchaseWithProviderError.hpp"
#include "JPurchaseVerificationProvider.hpp"
#include "JVariant_NullType_Array_NitroVerifyPurchaseWithProviderError_.hpp"
#include "JVariant_NullType_NitroVerifyPurchaseWithIapkitResult.hpp"
#include "JVariant_NullType_String.hpp"
#include "NitroVerifyPurchaseWithIapkitResult.hpp"
#include "NitroVerifyPurchaseWithProviderError.hpp"
#include "PurchaseVerificationProvider.hpp"
#include <NitroModules/JNull.hpp>
#include <NitroModules/Null.hpp>
#include <optional>
#include <string>
#include <variant>
#include <vector>

namespace margelo::nitro::iap {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NitroVerifyPurchaseWithProviderResult by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NitroVerifyPurchaseWithProviderResult toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldIapkit = clazz->getField<JVariant_NullType_NitroVerifyPurchaseWithIapkitResult>("iapkit");
      jni::local_ref<JVariant_NullType_NitroVerifyPurchaseWithIapkitResult> iapkit = this->getFieldValue(fieldIapkit);
      static const auto fieldErrors = clazz->getField<JVariant_NullType_Array_NitroVerifyPurchaseWithProviderError_>("errors");
      jni::local_ref<JVariant_NullType_Array_NitroVerifyPurchaseWithProviderError_> errors = this->getFieldValue(fieldErrors);
      static const auto fieldProvider = clazz->getField<JPurchaseVerificationProvider>("provider");
      jni::local_ref<JPurchaseVerificationProvider> provider = this->getFieldValue(fieldProvider);
      return NitroVerifyPurchaseWithProviderResult(
        iapkit != nullptr ? std::make_optional(iapkit->toCpp()) : std::nullopt,
        errors != nullptr ? std::make_optional(errors->toCpp()) : std::nullopt,
        provider->toCpp()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JNitroVerifyPurchaseWithProviderResult::javaobject> fromCpp(const NitroVerifyPurchaseWithProviderResult& value) {
      using JSignature = JNitroVerifyPurchaseWithProviderResult(jni::alias_ref<JVariant_NullType_NitroVerifyPurchaseWithIapkitResult>, jni::alias_ref<JVariant_NullType_Array_NitroVerifyPurchaseWithProviderError_>, jni::alias_ref<JPurchaseVerificationProvider>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.iapkit.has_value() ? JVariant_NullType_NitroVerifyPurchaseWithIapkitResult::fromCpp(value.iapkit.value()) : nullptr,
        value.errors.has_value() ? JVariant_NullType_Array_NitroVerifyPurchaseWithProviderError_::fromCpp(value.errors.value()) : nullptr,
        JPurchaseVerificationProvider::fromCpp(value.provider)
      );
    }
  };

} // namespace margelo::nitro::iap
