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

#pragma once

#include "HybridNitroFetchClientSpec.hpp"

// Forward declaration of `HybridNitroFetchClientSpec_cxx` to properly resolve imports.
namespace NitroFetch { class HybridNitroFetchClientSpec_cxx; }

// Forward declaration of `NitroResponse` to properly resolve imports.
namespace margelo::nitro::nitrofetch { struct NitroResponse; }
// Forward declaration of `NitroHeader` to properly resolve imports.
namespace margelo::nitro::nitrofetch { struct NitroHeader; }
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
namespace NitroModules { class ArrayBufferHolder; }
// Forward declaration of `NitroRequest` to properly resolve imports.
namespace margelo::nitro::nitrofetch { struct NitroRequest; }
// Forward declaration of `NitroRequestMethod` to properly resolve imports.
namespace margelo::nitro::nitrofetch { enum class NitroRequestMethod; }
// Forward declaration of `NitroFormDataPart` to properly resolve imports.
namespace margelo::nitro::nitrofetch { struct NitroFormDataPart; }

#include "NitroResponse.hpp"
#include <NitroModules/Promise.hpp>
#include <string>
#include "NitroHeader.hpp"
#include <vector>
#include <optional>
#include <NitroModules/ArrayBuffer.hpp>
#include <NitroModules/ArrayBufferHolder.hpp>
#include "NitroRequest.hpp"
#include "NitroRequestMethod.hpp"
#include "NitroFormDataPart.hpp"

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

namespace margelo::nitro::nitrofetch {

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

  public:
    // Get the Swift part
    inline NitroFetch::HybridNitroFetchClientSpec_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<HybridNitroFetchClientSpecSwift>(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 std::shared_ptr<Promise<NitroResponse>> request(const NitroRequest& req) override {
      auto __result = _swiftPart.request(std::forward<decltype(req)>(req));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> prefetch(const NitroRequest& req) override {
      auto __result = _swiftPart.prefetch(std::forward<decltype(req)>(req));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline NitroResponse requestSync(const NitroRequest& req) override {
      auto __result = _swiftPart.requestSync(std::forward<decltype(req)>(req));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline void cancelRequest(const std::string& requestId) override {
      auto __result = _swiftPart.cancelRequest(requestId);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
    }

  private:
    NitroFetch::HybridNitroFetchClientSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::nitrofetch
