///
/// MailAuthConfig.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 `MailAuthType` to properly resolve imports.
namespace margelo::nitro::mailengine { enum class MailAuthType; }

#include "MailAuthType.hpp"
#include <string>
#include <optional>

namespace margelo::nitro::mailengine {

  /**
   * A struct which can be represented as a JavaScript object (MailAuthConfig).
   */
  struct MailAuthConfig final {
  public:
    MailAuthType type     SWIFT_PRIVATE;
    std::string user     SWIFT_PRIVATE;
    std::optional<std::string> password     SWIFT_PRIVATE;
    std::optional<std::string> accessToken     SWIFT_PRIVATE;

  public:
    MailAuthConfig() = default;
    explicit MailAuthConfig(MailAuthType type, std::string user, std::optional<std::string> password, std::optional<std::string> accessToken): type(type), user(user), password(password), accessToken(accessToken) {}

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

} // namespace margelo::nitro::mailengine

namespace margelo::nitro {

  // C++ MailAuthConfig <> JS MailAuthConfig (object)
  template <>
  struct JSIConverter<margelo::nitro::mailengine::MailAuthConfig> final {
    static inline margelo::nitro::mailengine::MailAuthConfig fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::mailengine::MailAuthConfig(
        JSIConverter<margelo::nitro::mailengine::MailAuthType>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "user"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "password"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accessToken")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mailengine::MailAuthConfig& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "type"), JSIConverter<margelo::nitro::mailengine::MailAuthType>::toJSI(runtime, arg.type));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "user"), JSIConverter<std::string>::toJSI(runtime, arg.user));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "password"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.password));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "accessToken"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.accessToken));
      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<margelo::nitro::mailengine::MailAuthType>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "user")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "password")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accessToken")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
