///
/// JReadiumFile.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 "ReadiumFile.hpp"

#include "JLocator.hpp"
#include "JLocatorLocations.hpp"
#include "JLocatorText.hpp"
#include "Locator.hpp"
#include "LocatorLocations.hpp"
#include "LocatorText.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::readium {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct ReadiumFile by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    ReadiumFile toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldUrl = clazz->getField<jni::JString>("url");
      jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
      static const auto fieldInitialLocation = clazz->getField<JLocator>("initialLocation");
      jni::local_ref<JLocator> initialLocation = this->getFieldValue(fieldInitialLocation);
      return ReadiumFile(
        url->toStdString(),
        initialLocation != nullptr ? std::make_optional(initialLocation->toCpp()) : 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<JReadiumFile::javaobject> fromCpp(const ReadiumFile& value) {
      using JSignature = JReadiumFile(jni::alias_ref<jni::JString>, jni::alias_ref<JLocator>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.url),
        value.initialLocation.has_value() ? JLocator::fromCpp(value.initialLocation.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::readium
