///
/// SpeechErrorCode.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/NitroHash.hpp>)
#include <NitroModules/NitroHash.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif
#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::one {

  /**
   * An enum which can be represented as a JavaScript union (SpeechErrorCode).
   */
  enum class SpeechErrorCode {
    UNKNOWN      SWIFT_NAME(unknown) = 0,
    NOT_ALLOWED      SWIFT_NAME(notAllowed) = 1,
    SERVICE_NOT_ALLOWED      SWIFT_NAME(serviceNotAllowed) = 2,
    LANGUAGE_NOT_SUPPORTED      SWIFT_NAME(languageNotSupported) = 3,
    AUDIO_CAPTURE      SWIFT_NAME(audioCapture) = 4,
    INTERRUPTED      SWIFT_NAME(interrupted) = 5,
    NETWORK      SWIFT_NAME(network) = 6,
    BUSY      SWIFT_NAME(busy) = 7,
  } CLOSED_ENUM;

} // namespace margelo::nitro::one

namespace margelo::nitro {

  // C++ SpeechErrorCode <> JS SpeechErrorCode (union)
  template <>
  struct JSIConverter<margelo::nitro::one::SpeechErrorCode> final {
    static inline margelo::nitro::one::SpeechErrorCode fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
      switch (hashString(unionValue.c_str(), unionValue.size())) {
        case hashString("unknown"): return margelo::nitro::one::SpeechErrorCode::UNKNOWN;
        case hashString("not-allowed"): return margelo::nitro::one::SpeechErrorCode::NOT_ALLOWED;
        case hashString("service-not-allowed"): return margelo::nitro::one::SpeechErrorCode::SERVICE_NOT_ALLOWED;
        case hashString("language-not-supported"): return margelo::nitro::one::SpeechErrorCode::LANGUAGE_NOT_SUPPORTED;
        case hashString("audio-capture"): return margelo::nitro::one::SpeechErrorCode::AUDIO_CAPTURE;
        case hashString("interrupted"): return margelo::nitro::one::SpeechErrorCode::INTERRUPTED;
        case hashString("network"): return margelo::nitro::one::SpeechErrorCode::NETWORK;
        case hashString("busy"): return margelo::nitro::one::SpeechErrorCode::BUSY;
        default: [[unlikely]]
          throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum SpeechErrorCode - invalid value!");
      }
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::one::SpeechErrorCode arg) {
      switch (arg) {
        case margelo::nitro::one::SpeechErrorCode::UNKNOWN: return JSIConverter<std::string>::toJSI(runtime, "unknown");
        case margelo::nitro::one::SpeechErrorCode::NOT_ALLOWED: return JSIConverter<std::string>::toJSI(runtime, "not-allowed");
        case margelo::nitro::one::SpeechErrorCode::SERVICE_NOT_ALLOWED: return JSIConverter<std::string>::toJSI(runtime, "service-not-allowed");
        case margelo::nitro::one::SpeechErrorCode::LANGUAGE_NOT_SUPPORTED: return JSIConverter<std::string>::toJSI(runtime, "language-not-supported");
        case margelo::nitro::one::SpeechErrorCode::AUDIO_CAPTURE: return JSIConverter<std::string>::toJSI(runtime, "audio-capture");
        case margelo::nitro::one::SpeechErrorCode::INTERRUPTED: return JSIConverter<std::string>::toJSI(runtime, "interrupted");
        case margelo::nitro::one::SpeechErrorCode::NETWORK: return JSIConverter<std::string>::toJSI(runtime, "network");
        case margelo::nitro::one::SpeechErrorCode::BUSY: return JSIConverter<std::string>::toJSI(runtime, "busy");
        default: [[unlikely]]
          throw std::invalid_argument("Cannot convert SpeechErrorCode to JS - invalid value: "
                                    + std::to_string(static_cast<int>(arg)) + "!");
      }
    }
    static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
      if (!value.isString()) {
        return false;
      }
      std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
      switch (hashString(unionValue.c_str(), unionValue.size())) {
        case hashString("unknown"):
        case hashString("not-allowed"):
        case hashString("service-not-allowed"):
        case hashString("language-not-supported"):
        case hashString("audio-capture"):
        case hashString("interrupted"):
        case hashString("network"):
        case hashString("busy"):
          return true;
        default:
          return false;
      }
    }
  };

} // namespace margelo::nitro
