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

#pragma once

#include "HybridOneFetchSpec.hpp"

// Forward declaration of `HybridOneFetchSpec_cxx` to properly resolve imports.
namespace One { class HybridOneFetchSpec_cxx; }

// Forward declaration of `FetchNativeRequest` to properly resolve imports.
namespace margelo::nitro::one { struct FetchNativeRequest; }
// Forward declaration of `FetchHeader` to properly resolve imports.
namespace margelo::nitro::one { struct FetchHeader; }
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
namespace NitroModules { class ArrayBufferHolder; }
// Forward declaration of `FetchBlobRef` to properly resolve imports.
namespace margelo::nitro::one { struct FetchBlobRef; }
// Forward declaration of `FetchFormPart` to properly resolve imports.
namespace margelo::nitro::one { struct FetchFormPart; }
// Forward declaration of `FetchNativeResponse` to properly resolve imports.
namespace margelo::nitro::one { struct FetchNativeResponse; }

#include "FetchNativeRequest.hpp"
#include <string>
#include "FetchHeader.hpp"
#include <vector>
#include <NitroModules/ArrayBuffer.hpp>
#include <optional>
#include <NitroModules/ArrayBufferHolder.hpp>
#include "FetchBlobRef.hpp"
#include "FetchFormPart.hpp"
#include "FetchNativeResponse.hpp"
#include <functional>

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

namespace margelo::nitro::one {

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

  public:
    // Get the Swift part
    inline One::HybridOneFetchSpec_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<HybridOneFetchSpecSwift>(other)) {
        return _swiftPart.equals(otherCast->_swiftPart);
      }
      return false;
    }
    void dispose() noexcept override {
      _swiftPart.dispose();
    }
    std::string toString() override {
      return _swiftPart.toString();
    }

  public:
    // Properties
    

  public:
    // Methods
    inline void start(double id, const FetchNativeRequest& request, const std::function<void(const FetchNativeResponse& /* response */)>& onResponse, const std::function<void(const std::shared_ptr<ArrayBuffer>& /* chunk */)>& onChunk, const std::function<void()>& onComplete, const std::function<void(const std::string& /* message */)>& onError) override {
      auto __result = _swiftPart.start(std::forward<decltype(id)>(id), std::forward<decltype(request)>(request), onResponse, onChunk, onComplete, onError);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline void cancel(double id) override {
      auto __result = _swiftPart.cancel(std::forward<decltype(id)>(id));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }
    inline std::string storeBlob(const std::shared_ptr<ArrayBuffer>& bytes) override {
      auto __result = _swiftPart.storeBlob(ArrayBufferHolder(bytes));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }

  private:
    One::HybridOneFetchSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::one
