///
/// JNativeListItem.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 "NativeListItem.hpp"

#include <NitroModules/AnyMap.hpp>
#include <NitroModules/JAnyMap.hpp>
#include <optional>
#include <string>

namespace margelo::nitro::reactnativelist {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct NativeListItem by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    NativeListItem toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldKey = clazz->getField<jni::JString>("key");
      jni::local_ref<jni::JString> key = this->getFieldValue(fieldKey);
      static const auto fieldType = clazz->getField<jni::JString>("type");
      jni::local_ref<jni::JString> type = this->getFieldValue(fieldType);
      static const auto fieldWidth = clazz->getField<jni::JDouble>("width");
      jni::local_ref<jni::JDouble> width = this->getFieldValue(fieldWidth);
      static const auto fieldHeight = clazz->getField<jni::JDouble>("height");
      jni::local_ref<jni::JDouble> height = this->getFieldValue(fieldHeight);
      static const auto fieldData = clazz->getField<JAnyMap::javaobject>("data");
      jni::local_ref<JAnyMap::javaobject> data = this->getFieldValue(fieldData);
      return NativeListItem(
        key->toStdString(),
        type->toStdString(),
        width != nullptr ? std::make_optional(width->value()) : std::nullopt,
        height != nullptr ? std::make_optional(height->value()) : std::nullopt,
        data->cthis()->getMap()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JNativeListItem::javaobject> fromCpp(const NativeListItem& value) {
      using JSignature = JNativeListItem(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JAnyMap::javaobject>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.key),
        jni::make_jstring(value.type),
        value.width.has_value() ? jni::JDouble::valueOf(value.width.value()) : nullptr,
        value.height.has_value() ? jni::JDouble::valueOf(value.height.value()) : nullptr,
        JAnyMap::create(value.data)
      );
    }
  };

} // namespace margelo::nitro::reactnativelist
