///
/// HybridWebSocketSpecSwift.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 "HybridWebSocketSpec.hpp"

// Forward declaration of `HybridWebSocketSpec_cxx` to properly resolve imports.
namespace FastIO { class HybridWebSocketSpec_cxx; }

// Forward declaration of `ArrayBuffer` to properly resolve imports.
namespace NitroModules { class ArrayBuffer; }
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
namespace NitroModules { class ArrayBufferHolder; }

#include <string>
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/ArrayBufferHolder.hpp>
#include <functional>

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

namespace margelo::nitro::fastio {

  /**
   * The C++ part of HybridWebSocketSpec_cxx.swift.
   *
   * HybridWebSocketSpecSwift (C++) accesses HybridWebSocketSpec_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, HybridWebSocketSpec_cxx can directly inherit from the C++ class HybridWebSocketSpec
   * to simplify the whole structure and memory management.
   */
  class HybridWebSocketSpecSwift: public virtual HybridWebSocketSpec {
  public:
    // Constructor from a Swift instance
    explicit HybridWebSocketSpecSwift(const FastIO::HybridWebSocketSpec_cxx& swiftPart):
      HybridObject(HybridWebSocketSpec::TAG),
      _swiftPart(swiftPart) { }

  public:
    // Get the Swift part
    inline FastIO::HybridWebSocketSpec_cxx getSwiftPart() noexcept { return _swiftPart; }

  public:
    // Get memory pressure
    inline size_t getExternalMemorySize() noexcept override {
      return _swiftPart.getMemorySize();
    }

  public:
    // Properties
    

  public:
    // Methods
    inline void send(const std::string& message) override {
      auto __result = _swiftPart.send(message);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void sendArrayBuffer(const std::shared_ptr<ArrayBuffer>& buffer) override {
      auto __result = _swiftPart.sendArrayBuffer(ArrayBufferHolder(buffer));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void connect() override {
      auto __result = _swiftPart.connect();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void close(double code, const std::string& reason) override {
      auto __result = _swiftPart.close(std::forward<decltype(code)>(code), reason);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void ping() override {
      auto __result = _swiftPart.ping();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void onOpen(const std::function<void(const std::string& /* selectedProtocol */)>& callback) override {
      auto __result = _swiftPart.onOpen(callback);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void onClose(const std::function<void(double /* code */, const std::string& /* reason */)>& callback) override {
      auto __result = _swiftPart.onClose(callback);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void onError(const std::function<void(const std::string& /* error */)>& callback) override {
      auto __result = _swiftPart.onError(callback);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void onMessage(const std::function<void(const std::string& /* message */)>& callback) override {
      auto __result = _swiftPart.onMessage(callback);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void onArrayBuffer(const std::function<void(const std::shared_ptr<ArrayBuffer>& /* buffer */)>& callback) override {
      auto __result = _swiftPart.onArrayBuffer(callback);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }

  private:
    FastIO::HybridWebSocketSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::fastio
