///
/// JTextTrack.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once

#include <fbjni/fbjni.h>
#include "TextTrack.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::video {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct TextTrack by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    TextTrack 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 fieldLabel = clazz->getField<jni::JString>("label");
      jni::local_ref<jni::JString> label = this->getFieldValue(fieldLabel);
      static const auto fieldLanguage = clazz->getField<jni::JString>("language");
      jni::local_ref<jni::JString> language = this->getFieldValue(fieldLanguage);
      static const auto fieldSelected = clazz->getField<jboolean>("selected");
      jboolean selected = this->getFieldValue(fieldSelected);
      return TextTrack(
        id->toStdString(),
        label->toStdString(),
        language != nullptr ? std::make_optional(language->toStdString()) : std::nullopt,
        static_cast<bool>(selected)
      );
    }

  public:
    /**
     * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
     */
    [[maybe_unused]]
    static jni::local_ref<JTextTrack::javaobject> fromCpp(const TextTrack& value) {
      return newInstance(
        jni::make_jstring(value.id),
        jni::make_jstring(value.label),
        value.language.has_value() ? jni::make_jstring(value.language.value()) : nullptr,
        value.selected
      );
    }
  };

} // namespace margelo::nitro::video
