///
/// JMetadataSpec.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 "MetadataSpec.hpp"

#include "JWGS84Coordinate.hpp"
#include "WGS84Coordinate.hpp"
#include <NitroModules/JInstant.hpp>
#include <chrono>
#include <optional>
#include <string>
#include <unordered_map>

namespace margelo::nitro::videopipeline {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MetadataSpec by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MetadataSpec toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldLocation = clazz->getField<JWGS84Coordinate>("location");
      jni::local_ref<JWGS84Coordinate> location = this->getFieldValue(fieldLocation);
      static const auto fieldSoftware = clazz->getField<jni::JString>("software");
      jni::local_ref<jni::JString> software = this->getFieldValue(fieldSoftware);
      static const auto fieldCreationDate = clazz->getField<JInstant>("creationDate");
      jni::local_ref<JInstant> creationDate = this->getFieldValue(fieldCreationDate);
      static const auto fieldDescription = clazz->getField<jni::JString>("description");
      jni::local_ref<jni::JString> description = this->getFieldValue(fieldDescription);
      static const auto fieldCustom = clazz->getField<jni::JMap<jni::JString, jni::JString>>("custom");
      jni::local_ref<jni::JMap<jni::JString, jni::JString>> custom = this->getFieldValue(fieldCustom);
      return MetadataSpec(
        location != nullptr ? std::make_optional(location->toCpp()) : std::nullopt,
        software != nullptr ? std::make_optional(software->toStdString()) : std::nullopt,
        creationDate != nullptr ? std::make_optional(creationDate->toChrono()) : std::nullopt,
        description != nullptr ? std::make_optional(description->toStdString()) : std::nullopt,
        custom != nullptr ? std::make_optional([&]() {
          std::unordered_map<std::string, std::string> __map;
          __map.reserve(custom->size());
          for (const auto& __entry : *custom) {
            __map.emplace(__entry.first->toStdString(), __entry.second->toStdString());
          }
          return __map;
        }()) : 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<JMetadataSpec::javaobject> fromCpp(const MetadataSpec& value) {
      using JSignature = JMetadataSpec(jni::alias_ref<JWGS84Coordinate>, jni::alias_ref<jni::JString>, jni::alias_ref<JInstant>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.location.has_value() ? JWGS84Coordinate::fromCpp(value.location.value()) : nullptr,
        value.software.has_value() ? jni::make_jstring(value.software.value()) : nullptr,
        value.creationDate.has_value() ? JInstant::fromChrono(value.creationDate.value()) : nullptr,
        value.description.has_value() ? jni::make_jstring(value.description.value()) : nullptr,
        value.custom.has_value() ? [&]() -> jni::local_ref<jni::JMap<jni::JString, jni::JString>> {
          auto __map = jni::JHashMap<jni::JString, jni::JString>::create(value.custom.value().size());
          for (const auto& __entry : value.custom.value()) {
            __map->put(jni::make_jstring(__entry.first), jni::make_jstring(__entry.second));
          }
          return __map;
        }() : nullptr
      );
    }
  };

} // namespace margelo::nitro::videopipeline
