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

#pragma once

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

#include <string>

namespace margelo::nitro::fastio {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct Metadata by copying all values to C++.
     */
    [[maybe_unused]]
    Metadata toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldName = clazz->getField<jni::JString>("name");
      jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
      static const auto fieldPath = clazz->getField<jni::JString>("path");
      jni::local_ref<jni::JString> path = this->getFieldValue(fieldPath);
      static const auto fieldRoot = clazz->getField<jni::JString>("root");
      jni::local_ref<jni::JString> root = this->getFieldValue(fieldRoot);
      static const auto fieldSize = clazz->getField<double>("size");
      double size = this->getFieldValue(fieldSize);
      static const auto fieldType = clazz->getField<jni::JString>("type");
      jni::local_ref<jni::JString> type = this->getFieldValue(fieldType);
      static const auto fieldLastModified = clazz->getField<double>("lastModified");
      double lastModified = this->getFieldValue(fieldLastModified);
      return Metadata(
        name->toStdString(),
        path->toStdString(),
        root->toStdString(),
        size,
        type->toStdString(),
        lastModified
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JMetadata::javaobject> fromCpp(const Metadata& value) {
      return newInstance(
        jni::make_jstring(value.name),
        jni::make_jstring(value.path),
        jni::make_jstring(value.root),
        value.size,
        jni::make_jstring(value.type),
        value.lastModified
      );
    }
  };

} // namespace margelo::nitro::fastio
