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

#pragma once

#include "HybridSTTSpec.hpp"

// Forward declaration of `HybridSTTSpec_cxx` to properly resolve imports.
namespace MLXReactNative { class HybridSTTSpec_cxx; }

// Forward declaration of `STTLoadOptions` to properly resolve imports.
namespace margelo::nitro::mlxreactnative { struct STTLoadOptions; }
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
namespace NitroModules { class ArrayBufferHolder; }

#include <string>
#include <NitroModules/Promise.hpp>
#include "STTLoadOptions.hpp"
#include <optional>
#include <functional>
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/ArrayBufferHolder.hpp>

#include "MLXReactNative-Swift-Cxx-Umbrella.hpp"

namespace margelo::nitro::mlxreactnative {

  /**
   * The C++ part of HybridSTTSpec_cxx.swift.
   *
   * HybridSTTSpecSwift (C++) accesses HybridSTTSpec_cxx (Swift), and might
   * contain some additional bridging code for C++ <> Swift interop.
   *
   * Since this obviously introduces an overhead, I hope at some point in
   * the future, HybridSTTSpec_cxx can directly inherit from the C++ class HybridSTTSpec
   * to simplify the whole structure and memory management.
   */
  class HybridSTTSpecSwift: public virtual HybridSTTSpec {
  public:
    // Constructor from a Swift instance
    explicit HybridSTTSpecSwift(const MLXReactNative::HybridSTTSpec_cxx& swiftPart):
      HybridObject(HybridSTTSpec::TAG),
      _swiftPart(swiftPart) { }

  public:
    // Get the Swift part
    inline MLXReactNative::HybridSTTSpec_cxx& getSwiftPart() noexcept {
      return _swiftPart;
    }

  public:
    inline size_t getExternalMemorySize() noexcept override {
      return _swiftPart.getMemorySize();
    }
    void dispose() noexcept override {
      _swiftPart.dispose();
    }
    std::string toString() override {
      return _swiftPart.toString();
    }

  public:
    // Properties
    inline bool getIsLoaded() noexcept override {
      return _swiftPart.isLoaded();
    }
    inline bool getIsTranscribing() noexcept override {
      return _swiftPart.isTranscribing();
    }
    inline bool getIsListening() noexcept override {
      return _swiftPart.isListening();
    }
    inline std::string getModelId() noexcept override {
      auto __result = _swiftPart.getModelId();
      return __result;
    }

  public:
    // Methods
    inline std::shared_ptr<Promise<void>> load(const std::string& modelId, const std::optional<STTLoadOptions>& options) override {
      auto __result = _swiftPart.load(modelId, options);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::string>> transcribe(const std::shared_ptr<ArrayBuffer>& audio) override {
      auto __result = _swiftPart.transcribe(ArrayBufferHolder(audio));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::string>> transcribeStream(const std::shared_ptr<ArrayBuffer>& audio, const std::function<void(const std::string& /* token */)>& onToken) override {
      auto __result = _swiftPart.transcribeStream(ArrayBufferHolder(audio), onToken);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> startListening() override {
      auto __result = _swiftPart.startListening();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::string>> transcribeBuffer() override {
      auto __result = _swiftPart.transcribeBuffer();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::string>> stopListening() override {
      auto __result = _swiftPart.stopListening();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline void stop() override {
      auto __result = _swiftPart.stop();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void unload() override {
      auto __result = _swiftPart.unload();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }

  private:
    MLXReactNative::HybridSTTSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::mlxreactnative
