///
/// JMediaMetadata.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 "MediaMetadata.hpp"

#include "JLocationData.hpp"
#include "LocationData.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::mediatoolkit {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct MediaMetadata by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    MediaMetadata toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<jni::JString>("type");
      jni::local_ref<jni::JString> type = this->getFieldValue(fieldType);
      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 fieldSize = clazz->getField<double>("size");
      double size = this->getFieldValue(fieldSize);
      static const auto fieldDuration = clazz->getField<double>("duration");
      double duration = this->getFieldValue(fieldDuration);
      static const auto fieldMime = clazz->getField<jni::JString>("mime");
      jni::local_ref<jni::JString> mime = this->getFieldValue(fieldMime);
      static const auto fieldMake = clazz->getField<jni::JString>("make");
      jni::local_ref<jni::JString> make = this->getFieldValue(fieldMake);
      static const auto fieldModel = clazz->getField<jni::JString>("model");
      jni::local_ref<jni::JString> model = this->getFieldValue(fieldModel);
      static const auto fieldDatetime = clazz->getField<jni::JString>("datetime");
      jni::local_ref<jni::JString> datetime = this->getFieldValue(fieldDatetime);
      static const auto fieldLocation = clazz->getField<JLocationData>("location");
      jni::local_ref<JLocationData> location = this->getFieldValue(fieldLocation);
      static const auto fieldAperture = clazz->getField<jni::JDouble>("aperture");
      jni::local_ref<jni::JDouble> aperture = this->getFieldValue(fieldAperture);
      static const auto fieldExposureTime = clazz->getField<jni::JDouble>("exposureTime");
      jni::local_ref<jni::JDouble> exposureTime = this->getFieldValue(fieldExposureTime);
      static const auto fieldIso = clazz->getField<jni::JDouble>("iso");
      jni::local_ref<jni::JDouble> iso = this->getFieldValue(fieldIso);
      static const auto fieldFocalLength = clazz->getField<jni::JDouble>("focalLength");
      jni::local_ref<jni::JDouble> focalLength = this->getFieldValue(fieldFocalLength);
      return MediaMetadata(
        type->toStdString(),
        width,
        height,
        size,
        duration,
        mime->toStdString(),
        make != nullptr ? std::make_optional(make->toStdString()) : std::nullopt,
        model != nullptr ? std::make_optional(model->toStdString()) : std::nullopt,
        datetime != nullptr ? std::make_optional(datetime->toStdString()) : std::nullopt,
        location != nullptr ? std::make_optional(location->toCpp()) : std::nullopt,
        aperture != nullptr ? std::make_optional(aperture->value()) : std::nullopt,
        exposureTime != nullptr ? std::make_optional(exposureTime->value()) : std::nullopt,
        iso != nullptr ? std::make_optional(iso->value()) : std::nullopt,
        focalLength != nullptr ? std::make_optional(focalLength->value()) : 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<JMediaMetadata::javaobject> fromCpp(const MediaMetadata& value) {
      using JSignature = JMediaMetadata(jni::alias_ref<jni::JString>, double, double, double, double, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<JLocationData>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.type),
        value.width,
        value.height,
        value.size,
        value.duration,
        jni::make_jstring(value.mime),
        value.make.has_value() ? jni::make_jstring(value.make.value()) : nullptr,
        value.model.has_value() ? jni::make_jstring(value.model.value()) : nullptr,
        value.datetime.has_value() ? jni::make_jstring(value.datetime.value()) : nullptr,
        value.location.has_value() ? JLocationData::fromCpp(value.location.value()) : nullptr,
        value.aperture.has_value() ? jni::JDouble::valueOf(value.aperture.value()) : nullptr,
        value.exposureTime.has_value() ? jni::JDouble::valueOf(value.exposureTime.value()) : nullptr,
        value.iso.has_value() ? jni::JDouble::valueOf(value.iso.value()) : nullptr,
        value.focalLength.has_value() ? jni::JDouble::valueOf(value.focalLength.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::mediatoolkit
