///
/// JSelectionEvent.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 "SelectionEvent.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 "SelectionEvent" and the the Kotlin data class "SelectionEvent".
   */
  struct JSelectionEvent final: public jni::JavaClass<JSelectionEvent> {
  public:
    static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativereadium/SelectionEvent;";

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

} // namespace margelo::nitro::readium
