///
/// PlaceDetails.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 `AddressComponent` to properly resolve imports.
namespace margelo::nitro::googleplaces { struct AddressComponent; }

#include <string>
#include "AddressComponent.hpp"
#include <vector>

namespace margelo::nitro::googleplaces {

  /**
   * A struct which can be represented as a JavaScript object (PlaceDetails).
   */
  struct PlaceDetails final {
  public:
    std::string name     SWIFT_PRIVATE;
    std::string formatted_address     SWIFT_PRIVATE;
    std::string place_id     SWIFT_PRIVATE;
    double latitude     SWIFT_PRIVATE;
    double longitude     SWIFT_PRIVATE;
    std::vector<AddressComponent> address_components     SWIFT_PRIVATE;

  public:
    PlaceDetails() = default;
    explicit PlaceDetails(std::string name, std::string formatted_address, std::string place_id, double latitude, double longitude, std::vector<AddressComponent> address_components): name(name), formatted_address(formatted_address), place_id(place_id), latitude(latitude), longitude(longitude), address_components(address_components) {}

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

} // namespace margelo::nitro::googleplaces

namespace margelo::nitro {

  // C++ PlaceDetails <> JS PlaceDetails (object)
  template <>
  struct JSIConverter<margelo::nitro::googleplaces::PlaceDetails> final {
    static inline margelo::nitro::googleplaces::PlaceDetails fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
      jsi::Object obj = arg.asObject(runtime);
      return margelo::nitro::googleplaces::PlaceDetails(
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "formatted_address"))),
        JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "place_id"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latitude"))),
        JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "longitude"))),
        JSIConverter<std::vector<margelo::nitro::googleplaces::AddressComponent>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "address_components")))
      );
    }
    static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::googleplaces::PlaceDetails& arg) {
      jsi::Object obj(runtime);
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "name"), JSIConverter<std::string>::toJSI(runtime, arg.name));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "formatted_address"), JSIConverter<std::string>::toJSI(runtime, arg.formatted_address));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "place_id"), JSIConverter<std::string>::toJSI(runtime, arg.place_id));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "latitude"), JSIConverter<double>::toJSI(runtime, arg.latitude));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "longitude"), JSIConverter<double>::toJSI(runtime, arg.longitude));
      obj.setProperty(runtime, PropNameIDCache::get(runtime, "address_components"), JSIConverter<std::vector<margelo::nitro::googleplaces::AddressComponent>>::toJSI(runtime, arg.address_components));
      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, "name")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "formatted_address")))) return false;
      if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "place_id")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latitude")))) return false;
      if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "longitude")))) return false;
      if (!JSIConverter<std::vector<margelo::nitro::googleplaces::AddressComponent>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "address_components")))) return false;
      return true;
    }
  };

} // namespace margelo::nitro
