///
/// JPreloadConfig.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 "PreloadConfig.hpp"

#include <optional>

namespace margelo::nitro::aviation {

  using namespace facebook;

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

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

} // namespace margelo::nitro::aviation
