///
/// JPathStat.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 "PathStat.hpp"

#include <optional>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct PathStat by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    PathStat toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldExists = clazz->getField<jboolean>("exists");
      jboolean exists = this->getFieldValue(fieldExists);
      static const auto fieldIsDirectory = clazz->getField<jni::JBoolean>("isDirectory");
      jni::local_ref<jni::JBoolean> isDirectory = this->getFieldValue(fieldIsDirectory);
      return PathStat(
        static_cast<bool>(exists),
        isDirectory != nullptr ? std::make_optional(static_cast<bool>(isDirectory->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<JPathStat::javaobject> fromCpp(const PathStat& value) {
      using JSignature = JPathStat(jboolean, jni::alias_ref<jni::JBoolean>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.exists,
        value.isDirectory.has_value() ? jni::JBoolean::valueOf(value.isDirectory.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
