///
/// HapticEvent.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 `HapticEventType` to properly resolve imports.
namespace margelo::nitro::haptic { enum class HapticEventType; }
// Forward declaration of `HapticParameters` to properly resolve imports.
namespace margelo::nitro::haptic { struct HapticParameters; }

#include "HapticEventType.hpp"
#include <optional>
#include "HapticParameters.hpp"

namespace margelo::nitro::haptic {

  /**
   * A struct which can be represented as a JavaScript object (HapticEvent).
   */
  struct HapticEvent final {
  public:
    HapticEventType eventType     SWIFT_PRIVATE;
    double time     SWIFT_PRIVATE;
    std::optional<double> eventDuration     SWIFT_PRIVATE;
    std::optional<HapticParameters> parameters     SWIFT_PRIVATE;

  public:
    HapticEvent() = default;
    explicit HapticEvent(HapticEventType eventType, double time, std::optional<double> eventDuration, std::optional<HapticParameters> parameters): eventType(eventType), time(time), eventDuration(eventDuration), parameters(parameters) {}

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

} // namespace margelo::nitro::haptic

namespace margelo::nitro {

  // C++ HapticEvent <> JS HapticEvent (object)
  template <>
  struct JSIConverter<margelo::nitro::haptic::HapticEvent> final {
    static inline margelo::nitro::haptic::HapticEvent fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::haptic::HapticEvent(
        JSIConverter<margelo::nitro::haptic::HapticEventType>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "eventType"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "time"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "eventDuration"))),
        JSIConverter<std::optional<margelo::nitro::haptic::HapticParameters>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parameters")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::haptic::HapticEvent& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "eventType"), JSIConverter<margelo::nitro::haptic::HapticEventType>::toJSI(runtime, arg.eventType));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "time"), JSIConverter<double>::toJSI(runtime, arg.time));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "eventDuration"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.eventDuration));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "parameters"), JSIConverter<std::optional<margelo::nitro::haptic::HapticParameters>>::toJSI(runtime, arg.parameters));
      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::haptic::HapticEventType>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "eventType")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "time")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "eventDuration")))) return false;
      if (!JSIConverter<std::optional<margelo::nitro::haptic::HapticParameters>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "parameters")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
