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

#include "JHybridClarionAzureSpec.hpp"

// Forward declaration of `NativeTranscriptResult` to properly resolve imports.
namespace margelo::nitro::clarion::azure { struct NativeTranscriptResult; }
// Forward declaration of `NativeTranscriptSegment` to properly resolve imports.
namespace margelo::nitro::clarion::azure { struct NativeTranscriptSegment; }
// Forward declaration of `NativeAzureConfig` to properly resolve imports.
namespace margelo::nitro::clarion::azure { struct NativeAzureConfig; }
// Forward declaration of `NativeAzureError` to properly resolve imports.
namespace margelo::nitro::clarion::azure { struct NativeAzureError; }

#include <string>
#include <NitroModules/Promise.hpp>
#include <NitroModules/JPromise.hpp>
#include <NitroModules/JUnit.hpp>
#include "NativeTranscriptResult.hpp"
#include "JNativeTranscriptResult.hpp"
#include "NativeTranscriptSegment.hpp"
#include <vector>
#include "JNativeTranscriptSegment.hpp"
#include "NativeAzureConfig.hpp"
#include "JNativeAzureConfig.hpp"
#include <functional>
#include "JFunc_void_std__string.hpp"
#include <NitroModules/JNICallable.hpp>
#include "JFunc_void_double_double.hpp"
#include "JFunc_void_NativeTranscriptResult.hpp"
#include "NativeAzureError.hpp"
#include "JFunc_void_NativeAzureError.hpp"
#include "JNativeAzureError.hpp"
#include "JFunc_void_std__string_double.hpp"

namespace margelo::nitro::clarion::azure {

  std::shared_ptr<JHybridClarionAzureSpec> JHybridClarionAzureSpec::JavaPart::getJHybridClarionAzureSpec() {
    auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
    auto castHybridObject = std::dynamic_pointer_cast<JHybridClarionAzureSpec>(hybridObject);
    if (castHybridObject == nullptr) [[unlikely]] {
      throw std::runtime_error("Failed to downcast JHybridObject to JHybridClarionAzureSpec!");
    }
    return castHybridObject;
  }

  jni::local_ref<JHybridClarionAzureSpec::CxxPart::jhybriddata> JHybridClarionAzureSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
    return makeCxxInstance(jThis);
  }

  std::shared_ptr<JHybridObject> JHybridClarionAzureSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
    auto castJavaPart = jni::dynamic_ref_cast<JHybridClarionAzureSpec::JavaPart>(javaPart);
    if (castJavaPart == nullptr) [[unlikely]] {
      throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridClarionAzureSpec::JavaPart!");
    }
    return std::make_shared<JHybridClarionAzureSpec>(castJavaPart);
  }

  void JHybridClarionAzureSpec::CxxPart::registerNatives() {
    registerHybrid({
      makeNativeMethod("initHybrid", JHybridClarionAzureSpec::CxxPart::initHybrid),
    });
  }

  // Properties
  std::string JHybridClarionAzureSpec::getState() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getState");
    auto __result = method(_javaPart);
    return __result->toStdString();
  }

  // Methods
  std::shared_ptr<Promise<bool>> JHybridClarionAzureSpec::isAvailable(const NativeAzureConfig& config) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JNativeAzureConfig> /* config */)>("isAvailable");
    auto __result = method(_javaPart, JNativeAzureConfig::fromCpp(config));
    return [&]() {
      auto __promise = Promise<bool>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
        __promise->resolve(static_cast<bool>(__result->value()));
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<void>> JHybridClarionAzureSpec::prepare(const NativeAzureConfig& config) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JNativeAzureConfig> /* config */)>("prepare");
    auto __result = method(_javaPart, JNativeAzureConfig::fromCpp(config));
    return [&]() {
      auto __promise = Promise<void>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
        __promise->resolve();
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<void>> JHybridClarionAzureSpec::start() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("start");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<void>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
        __promise->resolve();
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<NativeTranscriptResult>> JHybridClarionAzureSpec::stop() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("stop");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<NativeTranscriptResult>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
        auto __result = jni::static_ref_cast<JNativeTranscriptResult>(__boxedResult);
        __promise->resolve(__result->toCpp());
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<void>> JHybridClarionAzureSpec::discard() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("discard");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<void>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
        __promise->resolve();
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<void>> JHybridClarionAzureSpec::release() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("release");
    auto __result = method(_javaPart);
    return [&]() {
      auto __promise = Promise<void>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
        __promise->resolve();
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  std::shared_ptr<Promise<void>> JHybridClarionAzureSpec::updateAuthToken(const std::string& token) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* token */)>("updateAuthToken");
    auto __result = method(_javaPart, jni::make_jstring(token));
    return [&]() {
      auto __promise = Promise<void>::create();
      __result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
        __promise->resolve();
      });
      __result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
        jni::JniException __jniError(__throwable);
        __promise->reject(std::make_exception_ptr(__jniError));
      });
      return __promise;
    }();
  }
  double JHybridClarionAzureSpec::addStateListener(const std::function<void(const std::string& /* state */)>& listener) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_std__string::javaobject> /* listener */)>("addStateListener_cxx");
    auto __result = method(_javaPart, JFunc_void_std__string_cxx::fromCpp(listener));
    return __result;
  }
  double JHybridClarionAzureSpec::addAudioLevelListener(const std::function<void(double /* rms */, double /* peak */)>& listener) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_double_double::javaobject> /* listener */)>("addAudioLevelListener_cxx");
    auto __result = method(_javaPart, JFunc_void_double_double_cxx::fromCpp(listener));
    return __result;
  }
  double JHybridClarionAzureSpec::addPartialListener(const std::function<void(const NativeTranscriptResult& /* result */)>& listener) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_NativeTranscriptResult::javaobject> /* listener */)>("addPartialListener_cxx");
    auto __result = method(_javaPart, JFunc_void_NativeTranscriptResult_cxx::fromCpp(listener));
    return __result;
  }
  double JHybridClarionAzureSpec::addFinalListener(const std::function<void(const NativeTranscriptResult& /* result */)>& listener) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_NativeTranscriptResult::javaobject> /* listener */)>("addFinalListener_cxx");
    auto __result = method(_javaPart, JFunc_void_NativeTranscriptResult_cxx::fromCpp(listener));
    return __result;
  }
  double JHybridClarionAzureSpec::addErrorListener(const std::function<void(const NativeAzureError& /* error */)>& listener) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_NativeAzureError::javaobject> /* listener */)>("addErrorListener_cxx");
    auto __result = method(_javaPart, JFunc_void_NativeAzureError_cxx::fromCpp(listener));
    return __result;
  }
  double JHybridClarionAzureSpec::addSpeechBoundaryListener(const std::function<void(const std::string& /* kind */, double /* offsetMs */)>& listener) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_std__string_double::javaobject> /* listener */)>("addSpeechBoundaryListener_cxx");
    auto __result = method(_javaPart, JFunc_void_std__string_double_cxx::fromCpp(listener));
    return __result;
  }
  void JHybridClarionAzureSpec::removeListener(double id) {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* id */)>("removeListener");
    method(_javaPart, id);
  }
  void JHybridClarionAzureSpec::removeAllListeners() {
    static const auto method = _javaPart->javaClassStatic()->getMethod<void()>("removeAllListeners");
    method(_javaPart);
  }

} // namespace margelo::nitro::clarion::azure
