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

namespace margelo::nitro::keyevent {

  /**
   * A struct which can be represented as a JavaScript object (KeyEventData).
   */
  struct KeyEventData {
  public:
    double keyCode     SWIFT_PRIVATE;
    double action     SWIFT_PRIVATE;
    std::string pressedKey     SWIFT_PRIVATE;
    std::optional<double> repeatCount     SWIFT_PRIVATE;

  public:
    KeyEventData() = default;
    explicit KeyEventData(double keyCode, double action, std::string pressedKey, std::optional<double> repeatCount): keyCode(keyCode), action(action), pressedKey(pressedKey), repeatCount(repeatCount) {}
  };

} // namespace margelo::nitro::keyevent

namespace margelo::nitro {

  // C++ KeyEventData <> JS KeyEventData (object)
  template <>
  struct JSIConverter<margelo::nitro::keyevent::KeyEventData> final {
    static inline margelo::nitro::keyevent::KeyEventData fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::keyevent::KeyEventData(
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "keyCode")),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "action")),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "pressedKey")),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "repeatCount"))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::keyevent::KeyEventData& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, "keyCode", JSIConverter<double>::toJSI(runtime, arg.keyCode));
      obj.setProperty(runtime, "action", JSIConverter<double>::toJSI(runtime, arg.action));
      obj.setProperty(runtime, "pressedKey", JSIConverter<std::string>::toJSI(runtime, arg.pressedKey));
      obj.setProperty(runtime, "repeatCount", JSIConverter<std::optional<double>>::toJSI(runtime, arg.repeatCount));
      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<double>::canConvert(runtime, obj.getProperty(runtime, "keyCode"))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "action"))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "pressedKey"))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "repeatCount"))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
