///
/// DfuState.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

namespace margelo::nitro::co::zyke::dfu {

  /**
   * An enum which can be represented as a JavaScript enum (DfuState).
   */
  enum class DfuState {
    CONNECTING      SWIFT_NAME(connecting) = 0,
    STARTING      SWIFT_NAME(starting) = 1,
    ENABLINGDFUMODE      SWIFT_NAME(enablingdfumode) = 2,
    UPLOADING      SWIFT_NAME(uploading) = 3,
    VALIDATING      SWIFT_NAME(validating) = 4,
    DISCONNECTING      SWIFT_NAME(disconnecting) = 5,
    COMPLETED      SWIFT_NAME(completed) = 6,
    ABORTED      SWIFT_NAME(aborted) = 7,
  } CLOSED_ENUM;

} // namespace margelo::nitro::co::zyke::dfu

namespace margelo::nitro {

  // C++ DfuState <> JS DfuState (enum)
  template <>
  struct JSIConverter<margelo::nitro::co::zyke::dfu::DfuState> final {
    static inline margelo::nitro::co::zyke::dfu::DfuState fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      int enumValue = JSIConverter<int>::fromJSI(runtime, arg);
      return static_cast<margelo::nitro::co::zyke::dfu::DfuState>(enumValue);
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::co::zyke::dfu::DfuState arg) {
      int enumValue = static_cast<int>(arg);
      return JSIConverter<int>::toJSI(runtime, enumValue);
    }
    static inline bool canConvert(jsi::Runtime&, const jsi::Value& value) {
      if (!value.isNumber()) {
        return false;
      }
      double number = value.getNumber();
      int integer = static_cast<int>(number);
      if (number != integer) {
        // The integer is not the same value as the double - we truncated floating points.
        // Enums are all integers, so the input floating point number is obviously invalid.
        return false;
      }
      // Check if we are within the bounds of the enum.
      return integer >= 0 && integer <= 7;
    }
  };

} // namespace margelo::nitro
