///
/// HybridOutputStreamSpecSwift.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 "HybridOutputStreamSpec.hpp"

// Forward declaration of `HybridOutputStreamSpec_cxx` to properly resolve imports.
namespace FastIO { class HybridOutputStreamSpec_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 <NitroModules/Promise.hpp>
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/ArrayBufferHolder.hpp>

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

namespace margelo::nitro::fastio {

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

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

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

  public:
    // Properties
    

  public:
    // Methods
    inline std::shared_ptr<Promise<void>> write(const std::shared_ptr<ArrayBuffer>& buffer) override {
      auto __result = _swiftPart.write(ArrayBufferHolder(buffer));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline void open() override {
      auto __result = _swiftPart.open();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void close() override {
      auto __result = _swiftPart.close();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }

  private:
    FastIO::HybridOutputStreamSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::fastio
