///
/// JAudioSessionConfig.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 "AudioSessionConfig.hpp"

#include "AudioCoexistence.hpp"
#include "AudioSessionCategory.hpp"
#include "AudioSessionMode.hpp"
#include "JAudioCoexistence.hpp"
#include "JAudioSessionCategory.hpp"
#include "JAudioSessionMode.hpp"
#include <optional>

namespace margelo::nitro::aviation {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct AudioSessionConfig by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    AudioSessionConfig toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldCategory = clazz->getField<JAudioSessionCategory>("category");
      jni::local_ref<JAudioSessionCategory> category = this->getFieldValue(fieldCategory);
      static const auto fieldMode = clazz->getField<JAudioSessionMode>("mode");
      jni::local_ref<JAudioSessionMode> mode = this->getFieldValue(fieldMode);
      static const auto fieldCoexistence = clazz->getField<JAudioCoexistence>("coexistence");
      jni::local_ref<JAudioCoexistence> coexistence = this->getFieldValue(fieldCoexistence);
      static const auto fieldAllowBluetooth = clazz->getField<jni::JBoolean>("allowBluetooth");
      jni::local_ref<jni::JBoolean> allowBluetooth = this->getFieldValue(fieldAllowBluetooth);
      static const auto fieldAllowAirPlay = clazz->getField<jni::JBoolean>("allowAirPlay");
      jni::local_ref<jni::JBoolean> allowAirPlay = this->getFieldValue(fieldAllowAirPlay);
      return AudioSessionConfig(
        category != nullptr ? std::make_optional(category->toCpp()) : std::nullopt,
        mode != nullptr ? std::make_optional(mode->toCpp()) : std::nullopt,
        coexistence != nullptr ? std::make_optional(coexistence->toCpp()) : std::nullopt,
        allowBluetooth != nullptr ? std::make_optional(static_cast<bool>(allowBluetooth->value())) : std::nullopt,
        allowAirPlay != nullptr ? std::make_optional(static_cast<bool>(allowAirPlay->value())) : 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<JAudioSessionConfig::javaobject> fromCpp(const AudioSessionConfig& value) {
      using JSignature = JAudioSessionConfig(jni::alias_ref<JAudioSessionCategory>, jni::alias_ref<JAudioSessionMode>, jni::alias_ref<JAudioCoexistence>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        value.category.has_value() ? JAudioSessionCategory::fromCpp(value.category.value()) : nullptr,
        value.mode.has_value() ? JAudioSessionMode::fromCpp(value.mode.value()) : nullptr,
        value.coexistence.has_value() ? JAudioCoexistence::fromCpp(value.coexistence.value()) : nullptr,
        value.allowBluetooth.has_value() ? jni::JBoolean::valueOf(value.allowBluetooth.value()) : nullptr,
        value.allowAirPlay.has_value() ? jni::JBoolean::valueOf(value.allowAirPlay.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::aviation
