///
/// JLocatorText.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 "LocatorText.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::readium {

  using namespace facebook;

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

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

} // namespace margelo::nitro::readium
