///
/// JSpeechSynthesisUtterance.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 "SpeechSynthesisUtterance.hpp"

#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct SpeechSynthesisUtterance by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    SpeechSynthesisUtterance toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldText = clazz->getField<jni::JString>("text");
      jni::local_ref<jni::JString> text = this->getFieldValue(fieldText);
      static const auto fieldLanguage = clazz->getField<jni::JString>("language");
      jni::local_ref<jni::JString> language = this->getFieldValue(fieldLanguage);
      static const auto fieldPitch = clazz->getField<jni::JDouble>("pitch");
      jni::local_ref<jni::JDouble> pitch = this->getFieldValue(fieldPitch);
      static const auto fieldRate = clazz->getField<jni::JDouble>("rate");
      jni::local_ref<jni::JDouble> rate = this->getFieldValue(fieldRate);
      static const auto fieldVoice = clazz->getField<jni::JString>("voice");
      jni::local_ref<jni::JString> voice = this->getFieldValue(fieldVoice);
      static const auto fieldVolume = clazz->getField<jni::JDouble>("volume");
      jni::local_ref<jni::JDouble> volume = this->getFieldValue(fieldVolume);
      return SpeechSynthesisUtterance(
        text->toStdString(),
        language != nullptr ? std::make_optional(language->toStdString()) : std::nullopt,
        pitch != nullptr ? std::make_optional(pitch->value()) : std::nullopt,
        rate != nullptr ? std::make_optional(rate->value()) : std::nullopt,
        voice != nullptr ? std::make_optional(voice->toStdString()) : 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<JSpeechSynthesisUtterance::javaobject> fromCpp(const SpeechSynthesisUtterance& value) {
      using JSignature = JSpeechSynthesisUtterance(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        jni::make_jstring(value.text),
        value.language.has_value() ? jni::make_jstring(value.language.value()) : nullptr,
        value.pitch.has_value() ? jni::JDouble::valueOf(value.pitch.value()) : nullptr,
        value.rate.has_value() ? jni::JDouble::valueOf(value.rate.value()) : nullptr,
        value.voice.has_value() ? jni::make_jstring(value.voice.value()) : nullptr,
        value.volume.has_value() ? jni::JDouble::valueOf(value.volume.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
