///
/// NitroReceiptValidationResultIOS.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/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
#if __has_include(<NitroModules/JSIHelpers.hpp>)
#include <NitroModules/JSIHelpers.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
#include <NitroModules/PropNameIDCache.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif

// Forward declaration of `NitroPurchase` to properly resolve imports.
namespace margelo::nitro::iap { struct NitroPurchase; }

#include <string>
#include <NitroModules/Null.hpp>
#include "NitroPurchase.hpp"
#include <variant>
#include <optional>

namespace margelo::nitro::iap {

  /**
   * A struct which can be represented as a JavaScript object (NitroReceiptValidationResultIOS).
   */
  struct NitroReceiptValidationResultIOS final {
  public:
    bool isValid     SWIFT_PRIVATE;
    std::string receiptData     SWIFT_PRIVATE;
    std::string jwsRepresentation     SWIFT_PRIVATE;
    std::optional<std::variant<nitro::NullType, NitroPurchase>> latestTransaction     SWIFT_PRIVATE;

  public:
    NitroReceiptValidationResultIOS() = default;
    explicit NitroReceiptValidationResultIOS(bool isValid, std::string receiptData, std::string jwsRepresentation, std::optional<std::variant<nitro::NullType, NitroPurchase>> latestTransaction): isValid(isValid), receiptData(receiptData), jwsRepresentation(jwsRepresentation), latestTransaction(latestTransaction) {}

  public:
    friend bool operator==(const NitroReceiptValidationResultIOS& lhs, const NitroReceiptValidationResultIOS& rhs) = default;
  };

} // namespace margelo::nitro::iap

namespace margelo::nitro {

  // C++ NitroReceiptValidationResultIOS <> JS NitroReceiptValidationResultIOS (object)
  template <>
  struct JSIConverter<margelo::nitro::iap::NitroReceiptValidationResultIOS> final {
    static inline margelo::nitro::iap::NitroReceiptValidationResultIOS fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::iap::NitroReceiptValidationResultIOS(
        JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isValid"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "receiptData"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jwsRepresentation"))),
        JSIConverter<std::optional<std::variant<nitro::NullType, margelo::nitro::iap::NitroPurchase>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latestTransaction")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::iap::NitroReceiptValidationResultIOS& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "isValid"), JSIConverter<bool>::toJSI(runtime, arg.isValid));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "receiptData"), JSIConverter<std::string>::toJSI(runtime, arg.receiptData));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "jwsRepresentation"), JSIConverter<std::string>::toJSI(runtime, arg.jwsRepresentation));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "latestTransaction"), JSIConverter<std::optional<std::variant<nitro::NullType, margelo::nitro::iap::NitroPurchase>>>::toJSI(runtime, arg.latestTransaction));
      return obj;
    }
    static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
      if (!value.isObject()) {
        return false;
      }
      jsi::Object obj = value.getObject(runtime);
      if (!nitro::isPlainObject(runtime, obj)) {
        return false;
      }
      if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isValid")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "receiptData")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jwsRepresentation")))) return false;
      if (!JSIConverter<std::optional<std::variant<nitro::NullType, margelo::nitro::iap::NitroPurchase>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latestTransaction")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
