///
/// JPickerResult.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include "PickerResult.hpp"

#include "JResultType.hpp"
#include "ResultType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::multipleimagepicker {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct PickerResult by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    PickerResult toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldLocalIdentifier = clazz->getField<jni::JString>("localIdentifier");
      jni::local_ref<jni::JString> localIdentifier = this->getFieldValue(fieldLocalIdentifier);
      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 fieldMime = clazz->getField<jni::JString>("mime");
      jni::local_ref<jni::JString> mime = this->getFieldValue(fieldMime);
      static const auto fieldSize = clazz->getField<double>("size");
      double size = this->getFieldValue(fieldSize);
      static const auto fieldBucketId = clazz->getField<jni::JDouble>("bucketId");
      jni::local_ref<jni::JDouble> bucketId = this->getFieldValue(fieldBucketId);
      static const auto fieldRealPath = clazz->getField<jni::JString>("realPath");
      jni::local_ref<jni::JString> realPath = this->getFieldValue(fieldRealPath);
      static const auto fieldParentFolderName = clazz->getField<jni::JString>("parentFolderName");
      jni::local_ref<jni::JString> parentFolderName = this->getFieldValue(fieldParentFolderName);
      static const auto fieldCreationDate = clazz->getField<jni::JDouble>("creationDate");
      jni::local_ref<jni::JDouble> creationDate = this->getFieldValue(fieldCreationDate);
      static const auto fieldCrop = clazz->getField<jni::JBoolean>("crop");
      jni::local_ref<jni::JBoolean> crop = this->getFieldValue(fieldCrop);
      static const auto fieldPath = clazz->getField<jni::JString>("path");
      jni::local_ref<jni::JString> path = this->getFieldValue(fieldPath);
      static const auto fieldType = clazz->getField<JResultType>("type");
      jni::local_ref<JResultType> type = this->getFieldValue(fieldType);
      static const auto fieldDuration = clazz->getField<jni::JDouble>("duration");
      jni::local_ref<jni::JDouble> duration = this->getFieldValue(fieldDuration);
      static const auto fieldThumbnail = clazz->getField<jni::JString>("thumbnail");
      jni::local_ref<jni::JString> thumbnail = this->getFieldValue(fieldThumbnail);
      static const auto fieldFileName = clazz->getField<jni::JString>("fileName");
      jni::local_ref<jni::JString> fileName = this->getFieldValue(fieldFileName);
      return PickerResult(
        localIdentifier->toStdString(),
        width,
        height,
        mime->toStdString(),
        size,
        bucketId != nullptr ? std::make_optional(bucketId->value()) : std::nullopt,
        realPath != nullptr ? std::make_optional(realPath->toStdString()) : std::nullopt,
        parentFolderName != nullptr ? std::make_optional(parentFolderName->toStdString()) : std::nullopt,
        creationDate != nullptr ? std::make_optional(creationDate->value()) : std::nullopt,
        crop != nullptr ? std::make_optional(static_cast<bool>(crop->value())) : std::nullopt,
        path->toStdString(),
        type->toCpp(),
        duration != nullptr ? std::make_optional(duration->value()) : std::nullopt,
        thumbnail != nullptr ? std::make_optional(thumbnail->toStdString()) : std::nullopt,
        fileName != nullptr ? std::make_optional(fileName->toStdString()) : 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<JPickerResult::javaobject> fromCpp(const PickerResult& value) {
      return newInstance(
        jni::make_jstring(value.localIdentifier),
        value.width,
        value.height,
        jni::make_jstring(value.mime),
        value.size,
        value.bucketId.has_value() ? jni::JDouble::valueOf(value.bucketId.value()) : nullptr,
        value.realPath.has_value() ? jni::make_jstring(value.realPath.value()) : nullptr,
        value.parentFolderName.has_value() ? jni::make_jstring(value.parentFolderName.value()) : nullptr,
        value.creationDate.has_value() ? jni::JDouble::valueOf(value.creationDate.value()) : nullptr,
        value.crop.has_value() ? jni::JBoolean::valueOf(value.crop.value()) : nullptr,
        jni::make_jstring(value.path),
        JResultType::fromCpp(value.type),
        value.duration.has_value() ? jni::JDouble::valueOf(value.duration.value()) : nullptr,
        value.thumbnail.has_value() ? jni::make_jstring(value.thumbnail.value()) : nullptr,
        value.fileName.has_value() ? jni::make_jstring(value.fileName.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::multipleimagepicker
