///
/// PurchaseTransaction.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 `PurchaseProductType` to properly resolve imports.
namespace margelo::nitro::one { enum class PurchaseProductType; }

#include <string>
#include "PurchaseProductType.hpp"
#include <optional>

namespace margelo::nitro::one {

  /**
   * A struct which can be represented as a JavaScript object (PurchaseTransaction).
   */
  struct PurchaseTransaction final {
  public:
    std::string id     SWIFT_PRIVATE;
    std::string originalId     SWIFT_PRIVATE;
    std::string productId     SWIFT_PRIVATE;
    PurchaseProductType productType     SWIFT_PRIVATE;
    double purchaseDateMs     SWIFT_PRIVATE;
    std::optional<double> expirationDateMs     SWIFT_PRIVATE;
    std::optional<double> revocationDateMs     SWIFT_PRIVATE;
    std::string jws     SWIFT_PRIVATE;

  public:
    PurchaseTransaction() = default;
    explicit PurchaseTransaction(std::string id, std::string originalId, std::string productId, PurchaseProductType productType, double purchaseDateMs, std::optional<double> expirationDateMs, std::optional<double> revocationDateMs, std::string jws): id(id), originalId(originalId), productId(productId), productType(productType), purchaseDateMs(purchaseDateMs), expirationDateMs(expirationDateMs), revocationDateMs(revocationDateMs), jws(jws) {}

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

} // namespace margelo::nitro::one

namespace margelo::nitro {

  // C++ PurchaseTransaction <> JS PurchaseTransaction (object)
  template <>
  struct JSIConverter<margelo::nitro::one::PurchaseTransaction> final {
    static inline margelo::nitro::one::PurchaseTransaction fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::one::PurchaseTransaction(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "originalId"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "productId"))),
        JSIConverter<margelo::nitro::one::PurchaseProductType>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "productType"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "purchaseDateMs"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "expirationDateMs"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "revocationDateMs"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jws")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::one::PurchaseTransaction& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::string>::toJSI(runtime, arg.id));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "originalId"), JSIConverter<std::string>::toJSI(runtime, arg.originalId));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "productId"), JSIConverter<std::string>::toJSI(runtime, arg.productId));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "productType"), JSIConverter<margelo::nitro::one::PurchaseProductType>::toJSI(runtime, arg.productType));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "purchaseDateMs"), JSIConverter<double>::toJSI(runtime, arg.purchaseDateMs));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "expirationDateMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.expirationDateMs));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "revocationDateMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.revocationDateMs));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "jws"), JSIConverter<std::string>::toJSI(runtime, arg.jws));
      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<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "originalId")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "productId")))) return false;
      if (!JSIConverter<margelo::nitro::one::PurchaseProductType>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "productType")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "purchaseDateMs")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "expirationDateMs")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "revocationDateMs")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "jws")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
