///
/// JSubtitleTrackSelection.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 "SubtitleTrackSelection.hpp"

#include "JSubtitleTrackSelectionType.hpp"
#include "SubtitleTrackSelectionType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::aviation {

  using namespace facebook;

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

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

} // namespace margelo::nitro::aviation
