///
/// JAdsConfig.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 "AdsConfig.hpp"

#include "CuePoint.hpp"
#include "JCuePoint.hpp"
#include <optional>
#include <string>
#include <vector>

namespace margelo::nitro::aviation {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct AdsConfig by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    AdsConfig toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldAdTagUrl = clazz->getField<jni::JString>("adTagUrl");
      jni::local_ref<jni::JString> adTagUrl = this->getFieldValue(fieldAdTagUrl);
      static const auto fieldEnablePreroll = clazz->getField<jni::JBoolean>("enablePreroll");
      jni::local_ref<jni::JBoolean> enablePreroll = this->getFieldValue(fieldEnablePreroll);
      static const auto fieldEnablePostroll = clazz->getField<jni::JBoolean>("enablePostroll");
      jni::local_ref<jni::JBoolean> enablePostroll = this->getFieldValue(fieldEnablePostroll);
      static const auto fieldCuePoints = clazz->getField<jni::JArrayClass<JCuePoint>>("cuePoints");
      jni::local_ref<jni::JArrayClass<JCuePoint>> cuePoints = this->getFieldValue(fieldCuePoints);
      static const auto fieldLanguage = clazz->getField<jni::JString>("language");
      jni::local_ref<jni::JString> language = this->getFieldValue(fieldLanguage);
      static const auto fieldMaxRedirects = clazz->getField<jni::JDouble>("maxRedirects");
      jni::local_ref<jni::JDouble> maxRedirects = this->getFieldValue(fieldMaxRedirects);
      return AdsConfig(
        adTagUrl != nullptr ? std::make_optional(adTagUrl->toStdString()) : std::nullopt,
        enablePreroll != nullptr ? std::make_optional(static_cast<bool>(enablePreroll->value())) : std::nullopt,
        enablePostroll != nullptr ? std::make_optional(static_cast<bool>(enablePostroll->value())) : std::nullopt,
        cuePoints != nullptr ? std::make_optional([&]() {
          size_t __size = cuePoints->size();
          std::vector<CuePoint> __vector;
          __vector.reserve(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            auto __element = cuePoints->getElement(__i);
            __vector.push_back(__element->toCpp());
          }
          return __vector;
        }()) : std::nullopt,
        language != nullptr ? std::make_optional(language->toStdString()) : std::nullopt,
        maxRedirects != nullptr ? std::make_optional(maxRedirects->value()) : 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<JAdsConfig::javaobject> fromCpp(const AdsConfig& value) {
      using JSignature = JAdsConfig(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JArrayClass<JCuePoint>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.adTagUrl.has_value() ? jni::make_jstring(value.adTagUrl.value()) : nullptr,
        value.enablePreroll.has_value() ? jni::JBoolean::valueOf(value.enablePreroll.value()) : nullptr,
        value.enablePostroll.has_value() ? jni::JBoolean::valueOf(value.enablePostroll.value()) : nullptr,
        value.cuePoints.has_value() ? [&]() {
          size_t __size = value.cuePoints.value().size();
          jni::local_ref<jni::JArrayClass<JCuePoint>> __array = jni::JArrayClass<JCuePoint>::newArray(__size);
          for (size_t __i = 0; __i < __size; __i++) {
            const auto& __element = value.cuePoints.value()[__i];
            auto __elementJni = JCuePoint::fromCpp(__element);
            __array->setElement(__i, *__elementJni);
          }
          return __array;
        }() : nullptr,
        value.language.has_value() ? jni::make_jstring(value.language.value()) : nullptr,
        value.maxRedirects.has_value() ? jni::JDouble::valueOf(value.maxRedirects.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::aviation
