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

#pragma once

#include "HybridOneContactsSpec.hpp"

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

// Forward declaration of `ContactsPermissionStatus` to properly resolve imports.
namespace margelo::nitro::one { enum class ContactsPermissionStatus; }
// Forward declaration of `ContactInfo` to properly resolve imports.
namespace margelo::nitro::one { struct ContactInfo; }
// Forward declaration of `ContactPostalAddress` to properly resolve imports.
namespace margelo::nitro::one { struct ContactPostalAddress; }
// Forward declaration of `ContactInput` to properly resolve imports.
namespace margelo::nitro::one { struct ContactInput; }
// Forward declaration of `ContactPostalAddressInput` to properly resolve imports.
namespace margelo::nitro::one { struct ContactPostalAddressInput; }
// Forward declaration of `ContactChanges` to properly resolve imports.
namespace margelo::nitro::one { struct ContactChanges; }

#include "ContactsPermissionStatus.hpp"
#include <NitroModules/Promise.hpp>
#include "ContactInfo.hpp"
#include <optional>
#include <string>
#include <vector>
#include "ContactPostalAddress.hpp"
#include "ContactInput.hpp"
#include "ContactPostalAddressInput.hpp"
#include "ContactChanges.hpp"

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

namespace margelo::nitro::one {

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

  public:
    // Get the Swift part
    inline One::HybridOneContactsSpec_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<HybridOneContactsSpecSwift>(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 ContactsPermissionStatus getPermissionStatus() override {
      auto __result = _swiftPart.getPermissionStatus();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<ContactsPermissionStatus>> requestPermission() override {
      auto __result = _swiftPart.requestPermission();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::optional<ContactInfo>>> pickContact() override {
      auto __result = _swiftPart.pickContact();
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::vector<ContactInfo>>> search(const std::string& name, double limit) override {
      auto __result = _swiftPart.search(name, std::forward<decltype(limit)>(limit));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<std::string>> create(const ContactInput& input) override {
      auto __result = _swiftPart.create(std::forward<decltype(input)>(input));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<ContactInfo>> update(const std::string& identifier, const ContactChanges& changes) override {
      auto __result = _swiftPart.update(identifier, std::forward<decltype(changes)>(changes));
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }
    inline std::shared_ptr<Promise<void>> remove(const std::string& identifier) override {
      auto __result = _swiftPart.remove(identifier);
      if (__result.hasError()) [[unlikely]] {
        std::rethrow_exception(__result.error());
      }
      auto __value = std::move(__result.value());
      return __value;
    }

  private:
    One::HybridOneContactsSpec_cxx _swiftPart;
  };

} // namespace margelo::nitro::one
