///
/// JDetailedFileInfo.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 "DetailedFileInfo.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct DetailedFileInfo by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    DetailedFileInfo toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldExists = clazz->getField<jboolean>("exists");
      jboolean exists = this->getFieldValue(fieldExists);
      static const auto fieldSize = clazz->getField<double>("size");
      double size = this->getFieldValue(fieldSize);
      static const auto fieldModificationTime = clazz->getField<jni::JDouble>("modificationTime");
      jni::local_ref<jni::JDouble> modificationTime = this->getFieldValue(fieldModificationTime);
      static const auto fieldCreationTime = clazz->getField<jni::JDouble>("creationTime");
      jni::local_ref<jni::JDouble> creationTime = this->getFieldValue(fieldCreationTime);
      static const auto fieldMimeType = clazz->getField<jni::JString>("mimeType");
      jni::local_ref<jni::JString> mimeType = this->getFieldValue(fieldMimeType);
      return DetailedFileInfo(
        static_cast<bool>(exists),
        size,
        modificationTime != nullptr ? std::make_optional(modificationTime->value()) : std::nullopt,
        creationTime != nullptr ? std::make_optional(creationTime->value()) : std::nullopt,
        mimeType->toStdString()
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JDetailedFileInfo::javaobject> fromCpp(const DetailedFileInfo& value) {
      using JSignature = JDetailedFileInfo(jboolean, double, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.exists,
        value.size,
        value.modificationTime.has_value() ? jni::JDouble::valueOf(value.modificationTime.value()) : nullptr,
        value.creationTime.has_value() ? jni::JDouble::valueOf(value.creationTime.value()) : nullptr,
        jni::make_jstring(value.mimeType)
      );
    }
  };

} // namespace margelo::nitro::one
