///
/// JPhotoLibraryAsset.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 "PhotoLibraryAsset.hpp"

#include "JPhotoLibraryMediaType.hpp"
#include "PhotoLibraryMediaType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct PhotoLibraryAsset by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    PhotoLibraryAsset toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldIdentifier = clazz->getField<jni::JString>("identifier");
      jni::local_ref<jni::JString> identifier = this->getFieldValue(fieldIdentifier);
      static const auto fieldMediaType = clazz->getField<JPhotoLibraryMediaType>("mediaType");
      jni::local_ref<JPhotoLibraryMediaType> mediaType = this->getFieldValue(fieldMediaType);
      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 fieldDurationMs = clazz->getField<double>("durationMs");
      double durationMs = this->getFieldValue(fieldDurationMs);
      static const auto fieldCreationDateMs = clazz->getField<jni::JDouble>("creationDateMs");
      jni::local_ref<jni::JDouble> creationDateMs = this->getFieldValue(fieldCreationDateMs);
      static const auto fieldIsFavorite = clazz->getField<jboolean>("isFavorite");
      jboolean isFavorite = this->getFieldValue(fieldIsFavorite);
      static const auto fieldIsLivePhoto = clazz->getField<jboolean>("isLivePhoto");
      jboolean isLivePhoto = this->getFieldValue(fieldIsLivePhoto);
      return PhotoLibraryAsset(
        identifier->toStdString(),
        mediaType->toCpp(),
        width,
        height,
        durationMs,
        creationDateMs != nullptr ? std::make_optional(creationDateMs->value()) : std::nullopt,
        static_cast<bool>(isFavorite),
        static_cast<bool>(isLivePhoto)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JPhotoLibraryAsset::javaobject> fromCpp(const PhotoLibraryAsset& value) {
      using JSignature = JPhotoLibraryAsset(jni::alias_ref<jni::JString>, jni::alias_ref<JPhotoLibraryMediaType>, double, double, double, jni::alias_ref<jni::JDouble>, jboolean, jboolean);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.identifier),
        JPhotoLibraryMediaType::fromCpp(value.mediaType),
        value.width,
        value.height,
        value.durationMs,
        value.creationDateMs.has_value() ? jni::JDouble::valueOf(value.creationDateMs.value()) : nullptr,
        value.isFavorite,
        value.isLivePhoto
      );
    }
  };

} // namespace margelo::nitro::one
