///
/// JLocatorLocations.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 "LocatorLocations.hpp"

#include <optional>

namespace margelo::nitro::readium {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct LocatorLocations by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    LocatorLocations toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldProgression = clazz->getField<double>("progression");
      double progression = this->getFieldValue(fieldProgression);
      static const auto fieldPosition = clazz->getField<jni::JDouble>("position");
      jni::local_ref<jni::JDouble> position = this->getFieldValue(fieldPosition);
      static const auto fieldTotalProgression = clazz->getField<jni::JDouble>("totalProgression");
      jni::local_ref<jni::JDouble> totalProgression = this->getFieldValue(fieldTotalProgression);
      return LocatorLocations(
        progression,
        position != nullptr ? std::make_optional(position->value()) : std::nullopt,
        totalProgression != nullptr ? std::make_optional(totalProgression->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<JLocatorLocations::javaobject> fromCpp(const LocatorLocations& value) {
      using JSignature = JLocatorLocations(double, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.progression,
        value.position.has_value() ? jni::JDouble::valueOf(value.position.value()) : nullptr,
        value.totalProgression.has_value() ? jni::JDouble::valueOf(value.totalProgression.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::readium
