///
/// Locator.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 `LocatorLocations` to properly resolve imports.
namespace margelo::nitro::readium { struct LocatorLocations; }
// Forward declaration of `LocatorText` to properly resolve imports.
namespace margelo::nitro::readium { struct LocatorText; }

#include <string>
#include <optional>
#include "LocatorLocations.hpp"
#include "LocatorText.hpp"

namespace margelo::nitro::readium {

  /**
   * A struct which can be represented as a JavaScript object (Locator).
   */
  struct Locator final {
  public:
    std::string href     SWIFT_PRIVATE;
    std::string type     SWIFT_PRIVATE;
    std::optional<double> target     SWIFT_PRIVATE;
    std::optional<std::string> title     SWIFT_PRIVATE;
    std::optional<LocatorLocations> locations     SWIFT_PRIVATE;
    std::optional<LocatorText> text     SWIFT_PRIVATE;

  public:
    Locator() = default;
    explicit Locator(std::string href, std::string type, std::optional<double> target, std::optional<std::string> title, std::optional<LocatorLocations> locations, std::optional<LocatorText> text): href(href), type(type), target(target), title(title), locations(locations), text(text) {}

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

} // namespace margelo::nitro::readium

namespace margelo::nitro {

  // C++ Locator <> JS Locator (object)
  template <>
  struct JSIConverter<margelo::nitro::readium::Locator> final {
    static inline margelo::nitro::readium::Locator fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::readium::Locator(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "href"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type"))),
        JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "target"))),
        JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "title"))),
        JSIConverter<std::optional<margelo::nitro::readium::LocatorLocations>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "locations"))),
        JSIConverter<std::optional<margelo::nitro::readium::LocatorText>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::readium::Locator& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "href"), JSIConverter<std::string>::toJSI(runtime, arg.href));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "type"), JSIConverter<std::string>::toJSI(runtime, arg.type));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "target"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.target));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "title"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.title));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "locations"), JSIConverter<std::optional<margelo::nitro::readium::LocatorLocations>>::toJSI(runtime, arg.locations));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "text"), JSIConverter<std::optional<margelo::nitro::readium::LocatorText>>::toJSI(runtime, arg.text));
      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, "href")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "type")))) return false;
      if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "target")))) return false;
      if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "title")))) return false;
      if (!JSIConverter<std::optional<margelo::nitro::readium::LocatorLocations>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "locations")))) return false;
      if (!JSIConverter<std::optional<margelo::nitro::readium::LocatorText>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "text")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
