///
/// NitroRequestMethod.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::nitrofetch {

  /**
   * An enum which can be represented as a JavaScript union (NitroRequestMethod).
   */
  enum class NitroRequestMethod {
    GET      SWIFT_NAME(get) = 0,
    HEAD      SWIFT_NAME(head) = 1,
    POST      SWIFT_NAME(post) = 2,
    PUT      SWIFT_NAME(put) = 3,
    PATCH      SWIFT_NAME(patch) = 4,
    DELETE      SWIFT_NAME(delete) = 5,
    OPTIONS      SWIFT_NAME(options) = 6,
  } CLOSED_ENUM;

} // namespace margelo::nitro::nitrofetch

namespace margelo::nitro {

  // C++ NitroRequestMethod <> JS NitroRequestMethod (union)
  template <>
  struct JSIConverter<margelo::nitro::nitrofetch::NitroRequestMethod> final {
    static inline margelo::nitro::nitrofetch::NitroRequestMethod 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("GET"): return margelo::nitro::nitrofetch::NitroRequestMethod::GET;
        case hashString("HEAD"): return margelo::nitro::nitrofetch::NitroRequestMethod::HEAD;
        case hashString("POST"): return margelo::nitro::nitrofetch::NitroRequestMethod::POST;
        case hashString("PUT"): return margelo::nitro::nitrofetch::NitroRequestMethod::PUT;
        case hashString("PATCH"): return margelo::nitro::nitrofetch::NitroRequestMethod::PATCH;
        case hashString("DELETE"): return margelo::nitro::nitrofetch::NitroRequestMethod::DELETE;
        case hashString("OPTIONS"): return margelo::nitro::nitrofetch::NitroRequestMethod::OPTIONS;
        default: [[unlikely]]
          throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum NitroRequestMethod - invalid value!");
      }
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrofetch::NitroRequestMethod arg) {
      switch (arg) {
        case margelo::nitro::nitrofetch::NitroRequestMethod::GET: return JSIConverter<std::string>::toJSI(runtime, "GET");
        case margelo::nitro::nitrofetch::NitroRequestMethod::HEAD: return JSIConverter<std::string>::toJSI(runtime, "HEAD");
        case margelo::nitro::nitrofetch::NitroRequestMethod::POST: return JSIConverter<std::string>::toJSI(runtime, "POST");
        case margelo::nitro::nitrofetch::NitroRequestMethod::PUT: return JSIConverter<std::string>::toJSI(runtime, "PUT");
        case margelo::nitro::nitrofetch::NitroRequestMethod::PATCH: return JSIConverter<std::string>::toJSI(runtime, "PATCH");
        case margelo::nitro::nitrofetch::NitroRequestMethod::DELETE: return JSIConverter<std::string>::toJSI(runtime, "DELETE");
        case margelo::nitro::nitrofetch::NitroRequestMethod::OPTIONS: return JSIConverter<std::string>::toJSI(runtime, "OPTIONS");
        default: [[unlikely]]
          throw std::invalid_argument("Cannot convert NitroRequestMethod 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("GET"):
        case hashString("HEAD"):
        case hashString("POST"):
        case hashString("PUT"):
        case hashString("PATCH"):
        case hashString("DELETE"):
        case hashString("OPTIONS"):
          return true;
        default:
          return false;
      }
    }
  };

} // namespace margelo::nitro
