///
/// NitroResponse.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 `NitroHeader` to properly resolve imports.
namespace margelo::nitro::nitrofetch { struct NitroHeader; }

#include <string>
#include "NitroHeader.hpp"
#include <vector>
#include <optional>
#include <NitroModules/ArrayBuffer.hpp>

namespace margelo::nitro::nitrofetch {

  /**
   * A struct which can be represented as a JavaScript object (NitroResponse).
   */
  struct NitroResponse final {
  public:
    std::string url     SWIFT_PRIVATE;
    double status     SWIFT_PRIVATE;
    std::string statusText     SWIFT_PRIVATE;
    bool ok     SWIFT_PRIVATE;
    bool redirected     SWIFT_PRIVATE;
    std::vector<NitroHeader> headers     SWIFT_PRIVATE;
    std::optional<std::string> bodyString     SWIFT_PRIVATE;
    std::optional<std::shared_ptr<ArrayBuffer>> bodyBytes     SWIFT_PRIVATE;

  public:
    NitroResponse() = default;
    explicit NitroResponse(std::string url, double status, std::string statusText, bool ok, bool redirected, std::vector<NitroHeader> headers, std::optional<std::string> bodyString, std::optional<std::shared_ptr<ArrayBuffer>> bodyBytes): url(url), status(status), statusText(statusText), ok(ok), redirected(redirected), headers(headers), bodyString(bodyString), bodyBytes(bodyBytes) {}

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

} // namespace margelo::nitro::nitrofetch

namespace margelo::nitro {

  // C++ NitroResponse <> JS NitroResponse (object)
  template <>
  struct JSIConverter<margelo::nitro::nitrofetch::NitroResponse> final {
    static inline margelo::nitro::nitrofetch::NitroResponse fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::nitrofetch::NitroResponse(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "status"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusText"))),
        JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ok"))),
        JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "redirected"))),
        JSIConverter<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::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrofetch::NitroResponse& 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, "status"), JSIConverter<double>::toJSI(runtime, arg.status));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "statusText"), JSIConverter<std::string>::toJSI(runtime, arg.statusText));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "ok"), JSIConverter<bool>::toJSI(runtime, arg.ok));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "redirected"), JSIConverter<bool>::toJSI(runtime, arg.redirected));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "headers"), JSIConverter<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::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.bodyBytes));
      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<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "status")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusText")))) return false;
      if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ok")))) return false;
      if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "redirected")))) return false;
      if (!JSIConverter<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::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bodyBytes")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
