///
/// JSeriesInfo.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 "SeriesInfo.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::readium {

  using namespace facebook;

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

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

} // namespace margelo::nitro::readium
