///
/// JInitConnectionConfig.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 "InitConnectionConfig.hpp"

#include "AlternativeBillingModeAndroid.hpp"
#include "BillingProgramAndroid.hpp"
#include "JAlternativeBillingModeAndroid.hpp"
#include "JBillingProgramAndroid.hpp"
#include <optional>

namespace margelo::nitro::iap {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct InitConnectionConfig by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    InitConnectionConfig toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldAlternativeBillingModeAndroid = clazz->getField<JAlternativeBillingModeAndroid>("alternativeBillingModeAndroid");
      jni::local_ref<JAlternativeBillingModeAndroid> alternativeBillingModeAndroid = this->getFieldValue(fieldAlternativeBillingModeAndroid);
      static const auto fieldEnableBillingProgramAndroid = clazz->getField<JBillingProgramAndroid>("enableBillingProgramAndroid");
      jni::local_ref<JBillingProgramAndroid> enableBillingProgramAndroid = this->getFieldValue(fieldEnableBillingProgramAndroid);
      return InitConnectionConfig(
        alternativeBillingModeAndroid != nullptr ? std::make_optional(alternativeBillingModeAndroid->toCpp()) : std::nullopt,
        enableBillingProgramAndroid != nullptr ? std::make_optional(enableBillingProgramAndroid->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<JInitConnectionConfig::javaobject> fromCpp(const InitConnectionConfig& value) {
      using JSignature = JInitConnectionConfig(jni::alias_ref<JAlternativeBillingModeAndroid>, jni::alias_ref<JBillingProgramAndroid>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.alternativeBillingModeAndroid.has_value() ? JAlternativeBillingModeAndroid::fromCpp(value.alternativeBillingModeAndroid.value()) : nullptr,
        value.enableBillingProgramAndroid.has_value() ? JBillingProgramAndroid::fromCpp(value.enableBillingProgramAndroid.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::iap
