///
/// NitroRequest.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 `NitroRequestMethod` to properly resolve imports.
namespace margelo::nitro::nitrofetch { enum class NitroRequestMethod; }
// Forward declaration of `NitroHeader` to properly resolve imports.
namespace margelo::nitro::nitrofetch { struct NitroHeader; }
// Forward declaration of `NitroFormDataPart` to properly resolve imports.
namespace margelo::nitro::nitrofetch { struct NitroFormDataPart; }

#include <string>
#include "NitroRequestMethod.hpp"
#include <optional>
#include "NitroHeader.hpp"
#include <vector>
#include "NitroFormDataPart.hpp"

namespace margelo::nitro::nitrofetch {

  /**
   * A struct which can be represented as a JavaScript object (NitroRequest).
   */
  struct NitroRequest final {
  public:
    std::string url     SWIFT_PRIVATE;
    std::optional<NitroRequestMethod> method     SWIFT_PRIVATE;
    std::optional<std::vector<NitroHeader>> headers     SWIFT_PRIVATE;
    std::optional<std::string> bodyString     SWIFT_PRIVATE;
    std::optional<std::string> bodyBytes     SWIFT_PRIVATE;
    std::optional<std::vector<NitroFormDataPart>> bodyFormData     SWIFT_PRIVATE;
    std::optional<double> timeoutMs     SWIFT_PRIVATE;
    std::optional<bool> followRedirects     SWIFT_PRIVATE;
    std::optional<double> prefetchCacheTtlMs     SWIFT_PRIVATE;
    std::optional<std::string> requestId     SWIFT_PRIVATE;

  public:
    NitroRequest() = default;
    explicit NitroRequest(std::string url, std::optional<NitroRequestMethod> method, std::optional<std::vector<NitroHeader>> headers, std::optional<std::string> bodyString, std::optional<std::string> bodyBytes, std::optional<std::vector<NitroFormDataPart>> bodyFormData, std::optional<double> timeoutMs, std::optional<bool> followRedirects, std::optional<double> prefetchCacheTtlMs, std::optional<std::string> requestId): url(url), method(method), headers(headers), bodyString(bodyString), bodyBytes(bodyBytes), bodyFormData(bodyFormData), timeoutMs(timeoutMs), followRedirects(followRedirects), prefetchCacheTtlMs(prefetchCacheTtlMs), requestId(requestId) {}

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

} // namespace margelo::nitro::nitrofetch

namespace margelo::nitro {

  // C++ NitroRequest <> JS NitroRequest (object)
  template <>
  struct JSIConverter<margelo::nitro::nitrofetch::NitroRequest> final {
    static inline margelo::nitro::nitrofetch::NitroRequest fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::nitrofetch::NitroRequest(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url"))),
        JSIConverter<std::optional<margelo::nitro::nitrofetch::NitroRequestMethod>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method"))),
        JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroHeader>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyString"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes"))),
        JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroFormDataPart>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyFormData"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timeoutMs"))),
        JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "followRedirects"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "prefetchCacheTtlMs"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestId")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::NitroRequest& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "url"), JSIConverter<std::string>::toJSI(runtime, arg.url));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "method"), JSIConverter<std::optional<margelo::nitro::nitrofetch::NitroRequestMethod>>::toJSI(runtime, arg.method));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "headers"), JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroHeader>>>::toJSI(runtime, arg.headers));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "bodyString"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyString));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.bodyBytes));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "bodyFormData"), JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroFormDataPart>>>::toJSI(runtime, arg.bodyFormData));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "timeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.timeoutMs));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "followRedirects"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.followRedirects));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "prefetchCacheTtlMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.prefetchCacheTtlMs));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "requestId"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.requestId));
      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<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url")))) return false;
      if (!JSIConverter<std::optional<margelo::nitro::nitrofetch::NitroRequestMethod>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method")))) return false;
      if (!JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroHeader>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyString")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes")))) return false;
      if (!JSIConverter<std::optional<std::vector<margelo::nitro::nitrofetch::NitroFormDataPart>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyFormData")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timeoutMs")))) return false;
      if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "followRedirects")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "prefetchCacheTtlMs")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "requestId")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
