///
/// JSubject.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 "Subject.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::readium {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct Subject by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    Subject 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 fieldSortAs = clazz->getField<jni::JString>("sortAs");
      jni::local_ref<jni::JString> sortAs = this->getFieldValue(fieldSortAs);
      static const auto fieldCode = clazz->getField<jni::JString>("code");
      jni::local_ref<jni::JString> code = this->getFieldValue(fieldCode);
      static const auto fieldScheme = clazz->getField<jni::JString>("scheme");
      jni::local_ref<jni::JString> scheme = this->getFieldValue(fieldScheme);
      return Subject(
        name->toStdString(),
        sortAs != nullptr ? std::make_optional(sortAs->toStdString()) : std::nullopt,
        code != nullptr ? std::make_optional(code->toStdString()) : std::nullopt,
        scheme != nullptr ? std::make_optional(scheme->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<JSubject::javaobject> fromCpp(const Subject& value) {
      using JSignature = JSubject(jni::alias_ref<jni::JString>, 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,
        jni::make_jstring(value.name),
        value.sortAs.has_value() ? jni::make_jstring(value.sortAs.value()) : nullptr,
        value.code.has_value() ? jni::make_jstring(value.code.value()) : nullptr,
        value.scheme.has_value() ? jni::make_jstring(value.scheme.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::readium
