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

#pragma once

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

#include <optional>
#include <string>

namespace margelo::nitro::nitrotexttospeech {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct TextToSpeechOptions by copying all values to C++.
     */
    [[maybe_unused]]
    TextToSpeechOptions toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldVoiceIdentifier = clazz->getField<jni::JString>("voiceIdentifier");
      jni::local_ref<jni::JString> voiceIdentifier = this->getFieldValue(fieldVoiceIdentifier);
      static const auto fieldRate = clazz->getField<jni::JDouble>("rate");
      jni::local_ref<jni::JDouble> rate = this->getFieldValue(fieldRate);
      static const auto fieldPitch = clazz->getField<jni::JDouble>("pitch");
      jni::local_ref<jni::JDouble> pitch = this->getFieldValue(fieldPitch);
      static const auto fieldPostUtteranceDelay = clazz->getField<jni::JDouble>("postUtteranceDelay");
      jni::local_ref<jni::JDouble> postUtteranceDelay = this->getFieldValue(fieldPostUtteranceDelay);
      static const auto fieldPreUtteranceDelay = clazz->getField<jni::JDouble>("preUtteranceDelay");
      jni::local_ref<jni::JDouble> preUtteranceDelay = this->getFieldValue(fieldPreUtteranceDelay);
      static const auto fieldVolume = clazz->getField<jni::JDouble>("volume");
      jni::local_ref<jni::JDouble> volume = this->getFieldValue(fieldVolume);
      return TextToSpeechOptions(
        voiceIdentifier != nullptr ? std::make_optional(voiceIdentifier->toStdString()) : std::nullopt,
        rate != nullptr ? std::make_optional(rate->value()) : std::nullopt,
        pitch != nullptr ? std::make_optional(pitch->value()) : std::nullopt,
        postUtteranceDelay != nullptr ? std::make_optional(postUtteranceDelay->value()) : std::nullopt,
        preUtteranceDelay != nullptr ? std::make_optional(preUtteranceDelay->value()) : std::nullopt,
        volume != nullptr ? std::make_optional(volume->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<JTextToSpeechOptions::javaobject> fromCpp(const TextToSpeechOptions& value) {
      return newInstance(
        value.voiceIdentifier.has_value() ? jni::make_jstring(value.voiceIdentifier.value()) : nullptr,
        value.rate.has_value() ? jni::JDouble::valueOf(value.rate.value()) : nullptr,
        value.pitch.has_value() ? jni::JDouble::valueOf(value.pitch.value()) : nullptr,
        value.postUtteranceDelay.has_value() ? jni::JDouble::valueOf(value.postUtteranceDelay.value()) : nullptr,
        value.preUtteranceDelay.has_value() ? jni::JDouble::valueOf(value.preUtteranceDelay.value()) : nullptr,
        value.volume.has_value() ? jni::JDouble::valueOf(value.volume.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::nitrotexttospeech
