///
/// JTikTokContentEventProperties.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 "TikTokContentEventProperties.hpp"

#include "JTikTokContent.hpp"
#include "TikTokContent.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::tiktokappevents {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct TikTokContentEventProperties by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    TikTokContentEventProperties toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldContentType = clazz->getField<jni::JString>("contentType");
      jni::local_ref<jni::JString> contentType = this->getFieldValue(fieldContentType);
      static const auto fieldContentId = clazz->getField<jni::JString>("contentId");
      jni::local_ref<jni::JString> contentId = this->getFieldValue(fieldContentId);
      static const auto fieldDescription = clazz->getField<jni::JString>("description");
      jni::local_ref<jni::JString> description = this->getFieldValue(fieldDescription);
      static const auto fieldCurrency = clazz->getField<jni::JString>("currency");
      jni::local_ref<jni::JString> currency = this->getFieldValue(fieldCurrency);
      static const auto fieldValue = clazz->getField<jni::JDouble>("value");
      jni::local_ref<jni::JDouble> value = this->getFieldValue(fieldValue);
      static const auto fieldOrderId = clazz->getField<jni::JString>("orderId");
      jni::local_ref<jni::JString> orderId = this->getFieldValue(fieldOrderId);
      static const auto fieldContents = clazz->getField<jni::JArrayClass<JTikTokContent>>("contents");
      jni::local_ref<jni::JArrayClass<JTikTokContent>> contents = this->getFieldValue(fieldContents);
      return TikTokContentEventProperties(
        contentType != nullptr ? std::make_optional(contentType->toStdString()) : std::nullopt,
        contentId != nullptr ? std::make_optional(contentId->toStdString()) : std::nullopt,
        description != nullptr ? std::make_optional(description->toStdString()) : std::nullopt,
        currency != nullptr ? std::make_optional(currency->toStdString()) : std::nullopt,
        value != nullptr ? std::make_optional(value->value()) : std::nullopt,
        orderId != nullptr ? std::make_optional(orderId->toStdString()) : std::nullopt,
        contents != nullptr ? std::make_optional([&]() {
          size_t __size = contents->size();
          std::vector<TikTokContent> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = contents->getElement(__i);
            __vector.push_back(__element->toCpp());
          }
          return __vector;
        }()) : 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<JTikTokContentEventProperties::javaobject> fromCpp(const TikTokContentEventProperties& value) {
      using JSignature = JTikTokContentEventProperties(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JArrayClass<JTikTokContent>>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.contentType.has_value() ? jni::make_jstring(value.contentType.value()) : nullptr,
        value.contentId.has_value() ? jni::make_jstring(value.contentId.value()) : nullptr,
        value.description.has_value() ? jni::make_jstring(value.description.value()) : nullptr,
        value.currency.has_value() ? jni::make_jstring(value.currency.value()) : nullptr,
        value.value.has_value() ? jni::JDouble::valueOf(value.value.value()) : nullptr,
        value.orderId.has_value() ? jni::make_jstring(value.orderId.value()) : nullptr,
        value.contents.has_value() ? [&]() {
          size_t __size = value.contents.value().size();
          jni::local_ref<jni::JArrayClass<JTikTokContent>> __array = jni::JArrayClass<JTikTokContent>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = value.contents.value()[__i];
            auto __elementJni = JTikTokContent::fromCpp(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }() : nullptr
      );
    }
  };

} // namespace margelo::nitro::tiktokappevents
