export default class OrderedObject {
    entries = []
    ids = {}
    indexes = []

    add(id, data) {
        if(this.ids[id]) {
            console.error(`Can't add item ${id}: id already exists`)
            throw new global.ServerError(400, `Member with this email already exists`)
        }
        this.entries.push(data)
        this.ids[id] = this.entries.length - 1
    }

    update(id, data) {
        let index = this.ids[id]
        this.entries[index] = data
    }

    delete(key) {
        if (typeof key === "number") {
            return this.entries[key]
        } else {
            return this.entries[this.ids[key]]
        }
    }
}