///
/// JSpeechEvent.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 "SpeechEvent.hpp"

#include "JSpeechErrorCode.hpp"
#include "JSpeechEventType.hpp"
#include "SpeechErrorCode.hpp"
#include "SpeechEventType.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::one {

  using namespace facebook;

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

  public:
    /**
     * Convert this Java/Kotlin-based struct to the C++ struct SpeechEvent by copying all values to C++.
     */
    [[maybe_unused]]
    [[nodiscard]]
    SpeechEvent toCpp() const {
      static const auto clazz = javaClassStatic();
      static const auto fieldType = clazz->getField<JSpeechEventType>("type");
      jni::local_ref<JSpeechEventType> type = this->getFieldValue(fieldType);
      static const auto fieldTranscript = clazz->getField<jni::JString>("transcript");
      jni::local_ref<jni::JString> transcript = this->getFieldValue(fieldTranscript);
      static const auto fieldError = clazz->getField<JSpeechErrorCode>("error");
      jni::local_ref<JSpeechErrorCode> error = this->getFieldValue(fieldError);
      static const auto fieldMessage = clazz->getField<jni::JString>("message");
      jni::local_ref<jni::JString> message = this->getFieldValue(fieldMessage);
      return SpeechEvent(
        type->toCpp(),
        transcript->toStdString(),
        error != nullptr ? std::make_optional(error->toCpp()) : std::nullopt,
        message != nullptr ? std::make_optional(message->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<JSpeechEvent::javaobject> fromCpp(const SpeechEvent& value) {
      using JSignature = JSpeechEvent(jni::alias_ref<JSpeechEventType>, jni::alias_ref<jni::JString>, jni::alias_ref<JSpeechErrorCode>, jni::alias_ref<jni::JString>);
      static const auto clazz = javaClassStatic();
      static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
      return create(
        clazz,
        JSpeechEventType::fromCpp(value.type),
        jni::make_jstring(value.transcript),
        value.error.has_value() ? JSpeechErrorCode::fromCpp(value.error.value()) : nullptr,
        value.message.has_value() ? jni::make_jstring(value.message.value()) : nullptr
      );
    }
  };

} // namespace margelo::nitro::one
