///
/// JSubtitle.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 "Subtitle.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::omni {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct Subtitle by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    Subtitle toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldId = clazz->getField<jni::JString>("id");
      jni::local_ref<jni::JString> id = this->getFieldValue(fieldId);
      static const auto fieldLink = clazz->getField<jni::JString>("link");
      jni::local_ref<jni::JString> link = this->getFieldValue(fieldLink);
      static const auto fieldMimeType = clazz->getField<jni::JString>("mimeType");
      jni::local_ref<jni::JString> mimeType = this->getFieldValue(fieldMimeType);
      static const auto fieldLanguage = clazz->getField<jni::JString>("language");
      jni::local_ref<jni::JString> language = this->getFieldValue(fieldLanguage);
      static const auto fieldLabel = clazz->getField<jni::JString>("label");
      jni::local_ref<jni::JString> label = this->getFieldValue(fieldLabel);
      return Subtitle(
        id->toStdString(),
        link->toStdString(),
        mimeType != nullptr ? std::make_optional(mimeType->toStdString()) : std::nullopt,
        language != nullptr ? std::make_optional(language->toStdString()) : std::nullopt,
        label != nullptr ? std::make_optional(label->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<JSubtitle::javaobject> fromCpp(const Subtitle& value) {
      using JSignature = JSubtitle(jni::alias_ref<jni::JString>, 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.id),
        jni::make_jstring(value.link),
        value.mimeType.has_value() ? jni::make_jstring(value.mimeType.value()) : nullptr,
        value.language.has_value() ? jni::make_jstring(value.language.value()) : nullptr,
        value.label.has_value() ? jni::make_jstring(value.label.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::omni
