#include <frostbite2D/base/object_registry.h>
#include <frostbite2D/2d/actor.h>
#include <frostbite2D/types/uuid.h>

namespace frostbite2D {

ObjectRegistry& ObjectRegistry::get() {
  static ObjectRegistry instance;
  return instance;
}

void ObjectRegistry::registerObject(const UUID& uuid, Actor* actor) {
  registry_[uuid.toString()] = actor;
}

void ObjectRegistry::unregisterObject(const UUID& uuid) {
  registry_.erase(uuid.toString());
}

Actor* ObjectRegistry::getObject(const UUID& uuid) {
  return getObject(uuid.toString());
}

Actor* ObjectRegistry::getObject(const std::string& uuidStr) {
  auto it = registry_.find(uuidStr);
  if (it != registry_.end()) {
    return it->second;
  }
  return nullptr;
}

bool ObjectRegistry::hasObject(const UUID& uuid) const {
  return hasObject(uuid.toString());
}

bool ObjectRegistry::hasObject(const std::string& uuidStr) const {
  return registry_.find(uuidStr) != registry_.end();
}

void ObjectRegistry::clear() {
  registry_.clear();
}

} // namespace frostbite2D
