///
/// FetchNativeRequest.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 `FetchHeader` to properly resolve imports.
namespace margelo::nitro::one { struct FetchHeader; }
// Forward declaration of `FetchBlobRef` to properly resolve imports.
namespace margelo::nitro::one { struct FetchBlobRef; }
// Forward declaration of `FetchFormPart` to properly resolve imports.
namespace margelo::nitro::one { struct FetchFormPart; }

#include <string>
#include "FetchHeader.hpp"
#include <vector>
#include <NitroModules/ArrayBuffer.hpp>
#include <optional>
#include "FetchBlobRef.hpp"
#include "FetchFormPart.hpp"

namespace margelo::nitro::one {

  /**
   * A struct which can be represented as a JavaScript object (FetchNativeRequest).
   */
  struct FetchNativeRequest final {
  public:
    std::string url     SWIFT_PRIVATE;
    std::string method     SWIFT_PRIVATE;
    std::vector<FetchHeader> headers     SWIFT_PRIVATE;
    std::optional<std::shared_ptr<ArrayBuffer>> body     SWIFT_PRIVATE;
    std::optional<FetchBlobRef> blob     SWIFT_PRIVATE;
    std::optional<std::vector<FetchFormPart>> form     SWIFT_PRIVATE;
    std::optional<std::string> boundary     SWIFT_PRIVATE;
    bool omitCredentials     SWIFT_PRIVATE;

  public:
    FetchNativeRequest() = default;
    explicit FetchNativeRequest(std::string url, std::string method, std::vector<FetchHeader> headers, std::optional<std::shared_ptr<ArrayBuffer>> body, std::optional<FetchBlobRef> blob, std::optional<std::vector<FetchFormPart>> form, std::optional<std::string> boundary, bool omitCredentials): url(url), method(method), headers(headers), body(body), blob(blob), form(form), boundary(boundary), omitCredentials(omitCredentials) {}

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

} // namespace margelo::nitro::one

namespace margelo::nitro {

  // C++ FetchNativeRequest <> JS FetchNativeRequest (object)
  template <>
  struct JSIConverter<margelo::nitro::one::FetchNativeRequest> final {
    static inline margelo::nitro::one::FetchNativeRequest fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::one::FetchNativeRequest(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "url"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method"))),
        JSIConverter<std::vector<margelo::nitro::one::FetchHeader>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers"))),
        JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "body"))),
        JSIConverter<std::optional<margelo::nitro::one::FetchBlobRef>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blob"))),
        JSIConverter<std::optional<std::vector<margelo::nitro::one::FetchFormPart>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "form"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "boundary"))),
        JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "omitCredentials")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::one::FetchNativeRequest& 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::string>::toJSI(runtime, arg.method));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "headers"), JSIConverter<std::vector<margelo::nitro::one::FetchHeader>>::toJSI(runtime, arg.headers));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "body"), JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::toJSI(runtime, arg.body));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "blob"), JSIConverter<std::optional<margelo::nitro::one::FetchBlobRef>>::toJSI(runtime, arg.blob));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "form"), JSIConverter<std::optional<std::vector<margelo::nitro::one::FetchFormPart>>>::toJSI(runtime, arg.form));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "boundary"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.boundary));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "omitCredentials"), JSIConverter<bool>::toJSI(runtime, arg.omitCredentials));
      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::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "method")))) return false;
      if (!JSIConverter<std::vector<margelo::nitro::one::FetchHeader>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "headers")))) return false;
      if (!JSIConverter<std::optional<std::shared_ptr<ArrayBuffer>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "body")))) return false;
      if (!JSIConverter<std::optional<margelo::nitro::one::FetchBlobRef>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blob")))) return false;
      if (!JSIConverter<std::optional<std::vector<margelo::nitro::one::FetchFormPart>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "form")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "boundary")))) return false;
      if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "omitCredentials")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
