import { world } from "@minecraft/server";
import Buffer from "./Buffer";
export default class Database {
    static save(id, data) {
        world.setDynamicProperty(id, data);
        Buffer.set_Data("world_database", id, data);
    }
    static load(id) {
        let data = Buffer.get_Data("world_database", id);
        if (data != undefined)
            return data;
        data = world.getDynamicProperty(id);
        if (data == undefined)
            return undefined;
        this.save(id, data);
        return data;
    }
    static delete(id) {
        Buffer.delete_Data("world_database", id);
        world.setDynamicProperty(id, undefined);
    }
    static save_All() {
        const ids = Array.from(Buffer.get("world_database").keys());
        for (let i = 0; i < ids.length; i++) {
            const data = this.load(ids[i]);
            this.save(ids[i], data);
        }
    }
    static delete_All() {
        const ids = world.getDynamicPropertyIds();
        for (let i = 0; i < ids.length; i++) {
            this.delete(ids[i]);
            Buffer.delete(ids[i]);
        }
    }
}
