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

#pragma once

#include "HybridOnePurchasesSpec.hpp"

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

// Forward declaration of `PurchaseProduct` to properly resolve imports.
namespace margelo::nitro::one { struct PurchaseProduct; }
// Forward declaration of `PurchaseProductType` to properly resolve imports.
namespace margelo::nitro::one { enum class PurchaseProductType; }
// Forward declaration of `PurchaseResult` to properly resolve imports.
namespace margelo::nitro::one { struct PurchaseResult; }
// Forward declaration of `PurchaseStatus` to properly resolve imports.
namespace margelo::nitro::one { enum class PurchaseStatus; }
// Forward declaration of `PurchaseTransaction` to properly resolve imports.
namespace margelo::nitro::one { struct PurchaseTransaction; }
// Forward declaration of `PurchaseUpdate` to properly resolve imports.
namespace margelo::nitro::one { struct PurchaseUpdate; }
// Forward declaration of `PurchaseUpdateStatus` to properly resolve imports.
namespace margelo::nitro::one { enum class PurchaseUpdateStatus; }

#include "PurchaseProduct.hpp"
#include <vector>
#include <NitroModules/Promise.hpp>
#include <string>
#include "PurchaseProductType.hpp"
#include <optional>
#include "PurchaseResult.hpp"
#include "PurchaseStatus.hpp"
#include "PurchaseTransaction.hpp"
#include <functional>
#include "PurchaseUpdate.hpp"
#include "PurchaseUpdateStatus.hpp"

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

namespace margelo::nitro::one {

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

  public:
    // Get the Swift part
    inline One::HybridOnePurchasesSpec_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<HybridOnePurchasesSpecSwift>(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<std::vector<PurchaseProduct>>> getProducts(const std::vector<std::string>& productIds) override {
      auto __result = _swiftPart.getProducts(productIds);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<PurchaseResult>> purchase(const std::string& productId, const std::optional<std::string>& appAccountToken) override {
      auto __result = _swiftPart.purchase(productId, appAccountToken);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::vector<PurchaseTransaction>>> getCurrentEntitlements() override {
      auto __result = _swiftPart.getCurrentEntitlements();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::vector<PurchaseTransaction>>> getUnfinishedTransactions() override {
      auto __result = _swiftPart.getUnfinishedTransactions();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> finishTransaction(const std::string& transactionId) override {
      auto __result = _swiftPart.finishTransaction(transactionId);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::function<void()> addTransactionListener(const std::function<void(const PurchaseUpdate& /* update */)>& onUpdate) override {
      auto __result = _swiftPart.addTransactionListener(onUpdate);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> sync() override {
      auto __result = _swiftPart.sync();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }

  private:
    One::HybridOnePurchasesSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::one
