///
/// ParseResultNative.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 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



#include <string>
#include <optional>

namespace margelo::nitro::hypermarkdown {

  /**
   * A struct which can be represented as a JavaScript object (ParseResultNative).
   */
  struct ParseResultNative final {
  public:
    bool success     SWIFT_PRIVATE;
    std::string ast     SWIFT_PRIVATE;
    std::optional<std::string> errorMessage     SWIFT_PRIVATE;
    std::optional<double> errorLine     SWIFT_PRIVATE;
    std::optional<double> errorColumn     SWIFT_PRIVATE;

  public:
    ParseResultNative() = default;
    explicit ParseResultNative(bool success, std::string ast, std::optional<std::string> errorMessage, std::optional<double> errorLine, std::optional<double> errorColumn): success(success), ast(ast), errorMessage(errorMessage), errorLine(errorLine), errorColumn(errorColumn) {}

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

} // namespace margelo::nitro::hypermarkdown

namespace margelo::nitro {

  // C++ ParseResultNative <> JS ParseResultNative (object)
  template <>
  struct JSIConverter<margelo::nitro::hypermarkdown::ParseResultNative> final {
    static inline margelo::nitro::hypermarkdown::ParseResultNative fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::hypermarkdown::ParseResultNative(
        JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "success"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ast"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorMessage"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorLine"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorColumn")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::hypermarkdown::ParseResultNative& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "success"), JSIConverter<bool>::toJSI(runtime, arg.success));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "ast"), JSIConverter<std::string>::toJSI(runtime, arg.ast));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "errorMessage"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.errorMessage));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "errorLine"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.errorLine));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "errorColumn"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.errorColumn));
      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<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "success")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ast")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorMessage")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorLine")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "errorColumn")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
