///
/// JAdvancedCommerceItemIOS.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 "AdvancedCommerceItemIOS.hpp"

#include "AdvancedCommerceItemDetailsIOS.hpp"
#include "AdvancedCommerceRefundIOS.hpp"
#include "JAdvancedCommerceItemDetailsIOS.hpp"
#include "JAdvancedCommerceRefundIOS.hpp"
#include "JVariant_NullType_AdvancedCommerceItemDetailsIOS.hpp"
#include "JVariant_NullType_Array_AdvancedCommerceRefundIOS_.hpp"
#include "JVariant_NullType_Double.hpp"
#include "JVariant_NullType_String.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 "AdvancedCommerceItemIOS" and the the Kotlin data class "AdvancedCommerceItemIOS".
   */
  struct JAdvancedCommerceItemIOS final: public jni::JavaClass<JAdvancedCommerceItemIOS> {
  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/AdvancedCommerceItemIOS;";

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct AdvancedCommerceItemIOS by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    AdvancedCommerceItemIOS toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldDetails = clazz->getField<JVariant_NullType_AdvancedCommerceItemDetailsIOS>("details");
      jni::local_ref<JVariant_NullType_AdvancedCommerceItemDetailsIOS> details = this->getFieldValue(fieldDetails);
      static const auto fieldRefunds = clazz->getField<JVariant_NullType_Array_AdvancedCommerceRefundIOS_>("refunds");
      jni::local_ref<JVariant_NullType_Array_AdvancedCommerceRefundIOS_> refunds = this->getFieldValue(fieldRefunds);
      static const auto fieldRevocationDate = clazz->getField<JVariant_NullType_Double>("revocationDate");
      jni::local_ref<JVariant_NullType_Double> revocationDate = this->getFieldValue(fieldRevocationDate);
      return AdvancedCommerceItemIOS(
        details != nullptr ? std::make_optional(details->toCpp()) : std::nullopt,
        refunds != nullptr ? std::make_optional(refunds->toCpp()) : std::nullopt,
        revocationDate != nullptr ? std::make_optional(revocationDate->toCpp()) : 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<JAdvancedCommerceItemIOS::javaobject> fromCpp(const AdvancedCommerceItemIOS& value) {
      using JSignature = JAdvancedCommerceItemIOS(jni::alias_ref<JVariant_NullType_AdvancedCommerceItemDetailsIOS>, jni::alias_ref<JVariant_NullType_Array_AdvancedCommerceRefundIOS_>, jni::alias_ref<JVariant_NullType_Double>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.details.has_value() ? JVariant_NullType_AdvancedCommerceItemDetailsIOS::fromCpp(value.details.value()) : nullptr,
        value.refunds.has_value() ? JVariant_NullType_Array_AdvancedCommerceRefundIOS_::fromCpp(value.refunds.value()) : nullptr,
        value.revocationDate.has_value() ? JVariant_NullType_Double::fromCpp(value.revocationDate.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::iap
