///
/// StorageMetadata.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 `SecurityLevel` to properly resolve imports.
namespace margelo::nitro::sensitiveinfo { enum class SecurityLevel; }
// Forward declaration of `StorageBackend` to properly resolve imports.
namespace margelo::nitro::sensitiveinfo { enum class StorageBackend; }
// Forward declaration of `AccessControl` to properly resolve imports.
namespace margelo::nitro::sensitiveinfo { enum class AccessControl; }

#include "SecurityLevel.hpp"
#include "StorageBackend.hpp"
#include "AccessControl.hpp"
#include <optional>
#include <string>

namespace margelo::nitro::sensitiveinfo {

  /**
   * A struct which can be represented as a JavaScript object (StorageMetadata).
   */
  struct StorageMetadata final {
  public:
    SecurityLevel securityLevel     SWIFT_PRIVATE;
    StorageBackend backend     SWIFT_PRIVATE;
    AccessControl accessControl     SWIFT_PRIVATE;
    double timestamp     SWIFT_PRIVATE;
    std::optional<double> keyVersion     SWIFT_PRIVATE;
    std::optional<std::string> integrityTag     SWIFT_PRIVATE;

  public:
    StorageMetadata() = default;
    explicit StorageMetadata(SecurityLevel securityLevel, StorageBackend backend, AccessControl accessControl, double timestamp, std::optional<double> keyVersion, std::optional<std::string> integrityTag): securityLevel(securityLevel), backend(backend), accessControl(accessControl), timestamp(timestamp), keyVersion(keyVersion), integrityTag(integrityTag) {}

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

} // namespace margelo::nitro::sensitiveinfo

namespace margelo::nitro {

  // C++ StorageMetadata <> JS StorageMetadata (object)
  template <>
  struct JSIConverter<margelo::nitro::sensitiveinfo::StorageMetadata> final {
    static inline margelo::nitro::sensitiveinfo::StorageMetadata fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::sensitiveinfo::StorageMetadata(
        JSIConverter<margelo::nitro::sensitiveinfo::SecurityLevel>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "securityLevel"))),
        JSIConverter<margelo::nitro::sensitiveinfo::StorageBackend>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backend"))),
        JSIConverter<margelo::nitro::sensitiveinfo::AccessControl>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accessControl"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timestamp"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "keyVersion"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "integrityTag")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::sensitiveinfo::StorageMetadata& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "securityLevel"), JSIConverter<margelo::nitro::sensitiveinfo::SecurityLevel>::toJSI(runtime, arg.securityLevel));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "backend"), JSIConverter<margelo::nitro::sensitiveinfo::StorageBackend>::toJSI(runtime, arg.backend));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "accessControl"), JSIConverter<margelo::nitro::sensitiveinfo::AccessControl>::toJSI(runtime, arg.accessControl));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "timestamp"), JSIConverter<double>::toJSI(runtime, arg.timestamp));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "keyVersion"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.keyVersion));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "integrityTag"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.integrityTag));
      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<margelo::nitro::sensitiveinfo::SecurityLevel>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "securityLevel")))) return false;
      if (!JSIConverter<margelo::nitro::sensitiveinfo::StorageBackend>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backend")))) return false;
      if (!JSIConverter<margelo::nitro::sensitiveinfo::AccessControl>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accessControl")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timestamp")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "keyVersion")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "integrityTag")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
