///
/// JAudioTrackSelection.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 "AudioTrackSelection.hpp"

#include "AudioTrackSelectionType.hpp"
#include "JAudioTrackSelectionType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::aviation {

  using namespace facebook;

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

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

} // namespace margelo::nitro::aviation
