///
/// JVideoInfo.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 "VideoInfo.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 "VideoInfo" and the the Kotlin data class "VideoInfo".
   */
  struct JVideoInfo final: public jni::JavaClass<JVideoInfo> {
  public:
    static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/videopipeline/VideoInfo;";

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct VideoInfo by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    VideoInfo toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldUri = clazz->getField<jni::JString>("uri");
      jni::local_ref<jni::JString> uri = this->getFieldValue(fieldUri);
      static const auto fieldDurationSec = clazz->getField<double>("durationSec");
      double durationSec = this->getFieldValue(fieldDurationSec);
      static const auto fieldWidth = clazz->getField<double>("width");
      double width = this->getFieldValue(fieldWidth);
      static const auto fieldHeight = clazz->getField<double>("height");
      double height = this->getFieldValue(fieldHeight);
      static const auto fieldCodedWidth = clazz->getField<double>("codedWidth");
      double codedWidth = this->getFieldValue(fieldCodedWidth);
      static const auto fieldCodedHeight = clazz->getField<double>("codedHeight");
      double codedHeight = this->getFieldValue(fieldCodedHeight);
      static const auto fieldFps = clazz->getField<double>("fps");
      double fps = this->getFieldValue(fieldFps);
      static const auto fieldBitRate = clazz->getField<double>("bitRate");
      double bitRate = this->getFieldValue(fieldBitRate);
      static const auto fieldFileSizeBytes = clazz->getField<double>("fileSizeBytes");
      double fileSizeBytes = this->getFieldValue(fieldFileSizeBytes);
      static const auto fieldCodec = clazz->getField<jni::JString>("codec");
      jni::local_ref<jni::JString> codec = this->getFieldValue(fieldCodec);
      static const auto fieldContainer = clazz->getField<jni::JString>("container");
      jni::local_ref<jni::JString> container = this->getFieldValue(fieldContainer);
      static const auto fieldHasAudio = clazz->getField<jboolean>("hasAudio");
      jboolean hasAudio = this->getFieldValue(fieldHasAudio);
      static const auto fieldIsHDR = clazz->getField<jboolean>("isHDR");
      jboolean isHDR = this->getFieldValue(fieldIsHDR);
      static const auto fieldRotation = clazz->getField<double>("rotation");
      double rotation = this->getFieldValue(fieldRotation);
      static const auto fieldCreationDate = clazz->getField<JInstant>("creationDate");
      jni::local_ref<JInstant> creationDate = this->getFieldValue(fieldCreationDate);
      static const auto fieldLocation = clazz->getField<JWGS84Coordinate>("location");
      jni::local_ref<JWGS84Coordinate> location = this->getFieldValue(fieldLocation);
      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 VideoInfo(
        uri->toStdString(),
        durationSec,
        width,
        height,
        codedWidth,
        codedHeight,
        fps,
        bitRate,
        fileSizeBytes,
        codec->toStdString(),
        container->toStdString(),
        static_cast<bool>(hasAudio),
        static_cast<bool>(isHDR),
        rotation,
        creationDate != nullptr ? std::make_optional(creationDate->toChrono()) : std::nullopt,
        location != nullptr ? std::make_optional(location->toCpp()) : 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<JVideoInfo::javaobject> fromCpp(const VideoInfo& value) {
      using JSignature = JVideoInfo(jni::alias_ref<jni::JString>, double, double, double, double, double, double, double, double, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jboolean, jboolean, double, jni::alias_ref<JInstant>, jni::alias_ref<JWGS84Coordinate>, 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,
        jni::make_jstring(value.uri),
        value.durationSec,
        value.width,
        value.height,
        value.codedWidth,
        value.codedHeight,
        value.fps,
        value.bitRate,
        value.fileSizeBytes,
        jni::make_jstring(value.codec),
        jni::make_jstring(value.container),
        value.hasAudio,
        value.isHDR,
        value.rotation,
        value.creationDate.has_value() ? JInstant::fromChrono(value.creationDate.value()) : nullptr,
        value.location.has_value() ? JWGS84Coordinate::fromCpp(value.location.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
