///
/// JCastLoadRequest.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 "CastLoadRequest.hpp"

#include <optional>
#include <string>
#include <unordered_map>

namespace margelo::nitro::omni {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct CastLoadRequest by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    CastLoadRequest toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldCastId = clazz->getField<jni::JString>("castId");
      jni::local_ref<jni::JString> castId = this->getFieldValue(fieldCastId);
      static const auto fieldCustomData = clazz->getField<jni::JMap<jni::JString, jni::JString>>("customData");
      jni::local_ref<jni::JMap<jni::JString, jni::JString>> customData = this->getFieldValue(fieldCustomData);
      static const auto fieldStartTime = clazz->getField<jni::JDouble>("startTime");
      jni::local_ref<jni::JDouble> startTime = this->getFieldValue(fieldStartTime);
      static const auto fieldAutoplay = clazz->getField<jboolean>("autoplay");
      jboolean autoplay = this->getFieldValue(fieldAutoplay);
      return CastLoadRequest(
        castId->toStdString(),
        customData != nullptr ? std::make_optional([&]() {
          std::unordered_map<std::string, std::string> __map;
          __map.reserve(customData->size());
          for (const auto& __entry : *customData) {
            __map.emplace(__entry.first->toStdString(), __entry.second->toStdString());
          }
          return __map;
        }()) : std::nullopt,
        startTime != nullptr ? std::make_optional(startTime->value()) : std::nullopt,
        static_cast<bool>(autoplay)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JCastLoadRequest::javaobject> fromCpp(const CastLoadRequest& value) {
      using JSignature = JCastLoadRequest(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JDouble>, jboolean);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.castId),
        value.customData.has_value() ? [&]() -> jni::local_ref<jni::JMap<jni::JString, jni::JString>> {
          auto __map = jni::JHashMap<jni::JString, jni::JString>::create(value.customData.value().size());
          for (const auto& __entry : value.customData.value()) {
            __map->put(jni::make_jstring(__entry.first), jni::make_jstring(__entry.second));
          }
          return __map;
        }() : nullptr,
        value.startTime.has_value() ? jni::JDouble::valueOf(value.startTime.value()) : nullptr,
        value.autoplay
      );
    }
  };

} // namespace margelo::nitro::omni
