///
/// MailAccountConfig.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 `MailServerConfig` to properly resolve imports.
namespace margelo::nitro::mailengine { struct MailServerConfig; }
// Forward declaration of `MailAuthConfig` to properly resolve imports.
namespace margelo::nitro::mailengine { struct MailAuthConfig; }

#include "MailServerConfig.hpp"
#include <optional>
#include "MailAuthConfig.hpp"
#include <string>

namespace margelo::nitro::mailengine {

  /**
   * A struct which can be represented as a JavaScript object (MailAccountConfig).
   */
  struct MailAccountConfig final {
  public:
    MailServerConfig imap     SWIFT_PRIVATE;
    std::optional<MailServerConfig> smtp     SWIFT_PRIVATE;
    MailAuthConfig auth     SWIFT_PRIVATE;
    std::optional<double> connectionTimeoutMs     SWIFT_PRIVATE;
    std::optional<std::string> id     SWIFT_PRIVATE;

  public:
    MailAccountConfig() = default;
    explicit MailAccountConfig(MailServerConfig imap, std::optional<MailServerConfig> smtp, MailAuthConfig auth, std::optional<double> connectionTimeoutMs, std::optional<std::string> id): imap(imap), smtp(smtp), auth(auth), connectionTimeoutMs(connectionTimeoutMs), id(id) {}

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

} // namespace margelo::nitro::mailengine

namespace margelo::nitro {

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

} // namespace margelo::nitro
