#include <functional>
#include <map>
#include <vector>
#include <string>

class GameDatabase {
    map<ObjectId, GameObject, greater<ObjectId>> dataBase;

 public:
    GameDatabase() = default;
    void Insert(ObjectId id, string name, size_t x, size_t y) {
        GameObject obj;
        obj.id = id;
        obj.name = name;
        obj.x = x;
        obj.y = y;
        dataBase[id] = obj;
    }
    void Remove(ObjectId id) {
        auto it = dataBase.find(id);
        if (it != dataBase.end())
            dataBase.erase(it);
    }
    vector<GameObject> DataByName(string name) const {
        vector<GameObject> re;
        for (auto it = dataBase.begin(); it != dataBase.end(); ++it) {
            if (it->second.name == name)
                re.push_back(it->second);
        }
        return re;
    }
    vector<GameObject> DataByPosition(size_t x, size_t y) const {
        vector<GameObject> re;
        for (auto it = dataBase.begin(); it != dataBase.end(); ++it) {
            if (it->second.x == x && it->second.y == y)
                re.push_back(it->second);
        }
        return re;
    }
    vector<GameObject> Data() const {
        vector<GameObject> re;
        for (auto it = dataBase.begin(); it != dataBase.end(); ++it) {
            re.push_back(it->second);
        }
        return re;
    }
};