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

#pragma once

#if __has_include(<NitroModules/NitroHash.hpp>)
#include <NitroModules/NitroHash.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/JSIConverter.hpp>)
#include <NitroModules/JSIConverter.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/NitroDefines.hpp>)
#include <NitroModules/NitroDefines.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif

namespace margelo::nitro::iap {

  /**
   * An enum which can be represented as a JavaScript union (IapkitPurchaseState).
   */
  enum class IapkitPurchaseState {
    PENDING      SWIFT_NAME(pending) = 0,
    UNKNOWN      SWIFT_NAME(unknown) = 1,
    ENTITLED      SWIFT_NAME(entitled) = 2,
    PENDING_ACKNOWLEDGMENT      SWIFT_NAME(pendingAcknowledgment) = 3,
    CANCELED      SWIFT_NAME(canceled) = 4,
    EXPIRED      SWIFT_NAME(expired) = 5,
    READY_TO_CONSUME      SWIFT_NAME(readyToConsume) = 6,
    CONSUMED      SWIFT_NAME(consumed) = 7,
    INAUTHENTIC      SWIFT_NAME(inauthentic) = 8,
  } CLOSED_ENUM;

} // namespace margelo::nitro::iap

namespace margelo::nitro {

  // C++ IapkitPurchaseState <> JS IapkitPurchaseState (union)
  template <>
  struct JSIConverter<margelo::nitro::iap::IapkitPurchaseState> final {
    static inline margelo::nitro::iap::IapkitPurchaseState fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
      switch (hashString(unionValue.c_str(), unionValue.size())) {
        case hashString("pending"): return margelo::nitro::iap::IapkitPurchaseState::PENDING;
        case hashString("unknown"): return margelo::nitro::iap::IapkitPurchaseState::UNKNOWN;
        case hashString("entitled"): return margelo::nitro::iap::IapkitPurchaseState::ENTITLED;
        case hashString("pending-acknowledgment"): return margelo::nitro::iap::IapkitPurchaseState::PENDING_ACKNOWLEDGMENT;
        case hashString("canceled"): return margelo::nitro::iap::IapkitPurchaseState::CANCELED;
        case hashString("expired"): return margelo::nitro::iap::IapkitPurchaseState::EXPIRED;
        case hashString("ready-to-consume"): return margelo::nitro::iap::IapkitPurchaseState::READY_TO_CONSUME;
        case hashString("consumed"): return margelo::nitro::iap::IapkitPurchaseState::CONSUMED;
        case hashString("inauthentic"): return margelo::nitro::iap::IapkitPurchaseState::INAUTHENTIC;
        default: [[unlikely]]
          throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum IapkitPurchaseState - invalid value!");
      }
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::iap::IapkitPurchaseState arg) {
      switch (arg) {
        case margelo::nitro::iap::IapkitPurchaseState::PENDING: return JSIConverter<std::string>::toJSI(runtime, "pending");
        case margelo::nitro::iap::IapkitPurchaseState::UNKNOWN: return JSIConverter<std::string>::toJSI(runtime, "unknown");
        case margelo::nitro::iap::IapkitPurchaseState::ENTITLED: return JSIConverter<std::string>::toJSI(runtime, "entitled");
        case margelo::nitro::iap::IapkitPurchaseState::PENDING_ACKNOWLEDGMENT: return JSIConverter<std::string>::toJSI(runtime, "pending-acknowledgment");
        case margelo::nitro::iap::IapkitPurchaseState::CANCELED: return JSIConverter<std::string>::toJSI(runtime, "canceled");
        case margelo::nitro::iap::IapkitPurchaseState::EXPIRED: return JSIConverter<std::string>::toJSI(runtime, "expired");
        case margelo::nitro::iap::IapkitPurchaseState::READY_TO_CONSUME: return JSIConverter<std::string>::toJSI(runtime, "ready-to-consume");
        case margelo::nitro::iap::IapkitPurchaseState::CONSUMED: return JSIConverter<std::string>::toJSI(runtime, "consumed");
        case margelo::nitro::iap::IapkitPurchaseState::INAUTHENTIC: return JSIConverter<std::string>::toJSI(runtime, "inauthentic");
        default: [[unlikely]]
          throw std::invalid_argument("Cannot convert IapkitPurchaseState to JS - invalid value: "
                                    + std::to_string(static_cast<int>(arg)) + "!");
      }
    }
    static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
      if (!value.isString()) {
        return false;
      }
      std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
      switch (hashString(unionValue.c_str(), unionValue.size())) {
        case hashString("pending"):
        case hashString("unknown"):
        case hashString("entitled"):
        case hashString("pending-acknowledgment"):
        case hashString("canceled"):
        case hashString("expired"):
        case hashString("ready-to-consume"):
        case hashString("consumed"):
        case hashString("inauthentic"):
          return true;
        default:
          return false;
      }
    }
  };

} // namespace margelo::nitro
