///
/// Metadata.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 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



#include <string>

namespace margelo::nitro::fastio {

  /**
   * A struct which can be represented as a JavaScript object (Metadata).
   */
  struct Metadata {
  public:
    std::string name     SWIFT_PRIVATE;
    std::string path     SWIFT_PRIVATE;
    std::string root     SWIFT_PRIVATE;
    double size     SWIFT_PRIVATE;
    std::string type     SWIFT_PRIVATE;
    double lastModified     SWIFT_PRIVATE;

  public:
    explicit Metadata(std::string name, std::string path, std::string root, double size, std::string type, double lastModified): name(name), path(path), root(root), size(size), type(type), lastModified(lastModified) {}
  };

} // namespace margelo::nitro::fastio

namespace margelo::nitro {

  using namespace margelo::nitro::fastio;

  // C++ Metadata <> JS Metadata (object)
  template <>
  struct JSIConverter<Metadata> {
    static inline Metadata fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return Metadata(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "name")),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "path")),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "root")),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "size")),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "type")),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "lastModified"))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const Metadata& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, "name", JSIConverter<std::string>::toJSI(runtime, arg.name));
      obj.setProperty(runtime, "path", JSIConverter<std::string>::toJSI(runtime, arg.path));
      obj.setProperty(runtime, "root", JSIConverter<std::string>::toJSI(runtime, arg.root));
      obj.setProperty(runtime, "size", JSIConverter<double>::toJSI(runtime, arg.size));
      obj.setProperty(runtime, "type", JSIConverter<std::string>::toJSI(runtime, arg.type));
      obj.setProperty(runtime, "lastModified", JSIConverter<double>::toJSI(runtime, arg.lastModified));
      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 (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "name"))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "path"))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "root"))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "size"))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "type"))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "lastModified"))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
