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

#pragma once

#include "HybridNetServerDriverSpec.hpp"

// Forward declaration of `HybridNetServerDriverSpec_cxx` to properly resolve imports.
namespace RustCNet { class HybridNetServerDriverSpec_cxx; }

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

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

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

namespace margelo::nitro::net {

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

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

  public:
    inline size_t getExternalMemorySize() noexcept override {
      return _swiftPart.getMemorySize();
    }
    bool equals(const std::shared_ptr<HybridObject>& other) override {
      if (auto otherCast = std::dynamic_pointer_cast<HybridNetServerDriverSpecSwift>(other)) {
        return _swiftPart.equals(otherCast->_swiftPart);
      }
      return false;
    }
    void dispose() noexcept override {
      _swiftPart.dispose();
    }
    std::string toString() override {
      return _swiftPart.toString();
    }

  public:
    // Properties
    inline std::function<void(double /* event */, const std::shared_ptr<ArrayBuffer>& /* data */)> getOnEvent() noexcept override {
      auto __result = _swiftPart.getOnEvent();
      return __result;
    }
    inline void setOnEvent(const std::function<void(double /* event */, const std::shared_ptr<ArrayBuffer>& /* data */)>& onEvent) noexcept override {
      _swiftPart.setOnEvent(onEvent);
    }
    inline double getMaxConnections() noexcept override {
      return _swiftPart.getMaxConnections();
    }
    inline void setMaxConnections(double maxConnections) noexcept override {
      _swiftPart.setMaxConnections(std::forward<decltype(maxConnections)>(maxConnections));
    }

  public:
    // Methods
    inline void listen(double port, std::optional<double> backlog, std::optional<bool> ipv6Only, std::optional<bool> reusePort) override {
      auto __result = _swiftPart.listen(std::forward<decltype(port)>(port), backlog, ipv6Only, reusePort);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void listenTLS(double port, double secureContextId, std::optional<double> backlog, std::optional<bool> ipv6Only, std::optional<bool> reusePort) override {
      auto __result = _swiftPart.listenTLS(std::forward<decltype(port)>(port), std::forward<decltype(secureContextId)>(secureContextId), backlog, ipv6Only, reusePort);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void listenUnix(const std::string& path, std::optional<double> backlog) override {
      auto __result = _swiftPart.listenUnix(path, backlog);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void listenTLSUnix(const std::string& path, double secureContextId, std::optional<double> backlog) override {
      auto __result = _swiftPart.listenTLSUnix(path, std::forward<decltype(secureContextId)>(secureContextId), backlog);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void listenHandle(double fd, std::optional<double> backlog) override {
      auto __result = _swiftPart.listenHandle(std::forward<decltype(fd)>(fd), backlog);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline std::string getLocalAddress() override {
      auto __result = _swiftPart.getLocalAddress();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline void close() override {
      auto __result = _swiftPart.close();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }

  private:
    RustCNet::HybridNetServerDriverSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::net
