///
/// JUnifiedRiveEvent.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 "UnifiedRiveEvent.hpp"

#include "JEventPropertiesOutput.hpp"
#include "JRiveEventType.hpp"
#include "RiveEventType.hpp"
#include <optional>
#include <string>
#include <unordered_map>
#include <variant>

namespace margelo::nitro::rive {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct UnifiedRiveEvent by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    UnifiedRiveEvent toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldName = clazz->getField<jni::JString>("name");
      jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
      static const auto fieldType = clazz->getField<JRiveEventType>("type");
      jni::local_ref<JRiveEventType> type = this->getFieldValue(fieldType);
      static const auto fieldDelay = clazz->getField<jni::JDouble>("delay");
      jni::local_ref<jni::JDouble> delay = this->getFieldValue(fieldDelay);
      static const auto fieldProperties = clazz->getField<jni::JMap<jni::JString, JEventPropertiesOutput>>("properties");
      jni::local_ref<jni::JMap<jni::JString, JEventPropertiesOutput>> properties = this->getFieldValue(fieldProperties);
      static const auto fieldUrl = clazz->getField<jni::JString>("url");
      jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
      static const auto fieldTarget = clazz->getField<jni::JString>("target");
      jni::local_ref<jni::JString> target = this->getFieldValue(fieldTarget);
      return UnifiedRiveEvent(
        name->toStdString(),
        type->toCpp(),
        delay != nullptr ? std::make_optional(delay->value()) : std::nullopt,
        properties != nullptr ? std::make_optional([&]() {
          std::unordered_map<std::string, std::variant<bool, std::string, double>> __map;
          __map.reserve(properties->size());
          for (const auto& __entry : *properties) {
            __map.emplace(__entry.first->toStdString(), __entry.second->toCpp());
          }
          return __map;
        }()) : std::nullopt,
        url != nullptr ? std::make_optional(url->toStdString()) : std::nullopt,
        target != nullptr ? std::make_optional(target->toStdString()) : 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<JUnifiedRiveEvent::javaobject> fromCpp(const UnifiedRiveEvent& value) {
      using JSignature = JUnifiedRiveEvent(jni::alias_ref<jni::JString>, jni::alias_ref<JRiveEventType>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JMap<jni::JString, JEventPropertiesOutput>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.name),
        JRiveEventType::fromCpp(value.type),
        value.delay.has_value() ? jni::JDouble::valueOf(value.delay.value()) : nullptr,
        value.properties.has_value() ? [&]() -> jni::local_ref<jni::JMap<jni::JString, JEventPropertiesOutput>> {
          auto __map = jni::JHashMap<jni::JString, JEventPropertiesOutput>::create(value.properties.value().size());
          for (const auto& __entry : value.properties.value()) {
            __map->put(jni::make_jstring(__entry.first), JEventPropertiesOutput::fromCpp(__entry.second));
          }
          return __map;
        }() : nullptr,
        value.url.has_value() ? jni::make_jstring(value.url.value()) : nullptr,
        value.target.has_value() ? jni::make_jstring(value.target.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::rive
