import * as db from "../utils/database/index";
export class DeathTally {
    static addKill(player, victim) {
        var _a, _b;
        const playerData = (_a = this.database.Tables.players.getEntry(player)) !== null && _a !== void 0 ? _a : { kills: {}, deaths: 0 };
        playerData.kills[victim] = ((_b = playerData.kills[victim]) !== null && _b !== void 0 ? _b : 0) + 1;
        this.database.Tables.players.setEntry(player, playerData);
    }
    static addDeath(player) {
        var _a;
        const playerData = (_a = this.database.Tables.players.getEntry(player)) !== null && _a !== void 0 ? _a : { kills: {}, deaths: 0 };
        playerData.deaths++;
        this.database.Tables.players.setEntry(player, playerData);
    }
    static getEntityKills(player, victim) {
        var _a, _b;
        const playerData = (_a = this.database.Tables.players.getEntry(player)) !== null && _a !== void 0 ? _a : { kills: {}, deaths: 0 };
        return (_b = playerData.kills[victim]) !== null && _b !== void 0 ? _b : 0;
    }
    static getEntityKillsTotal(victim) {
        let total = 0;
        this.database.Tables.players.forEach((data, key) => {
            var _a;
            total += (_a = data.kills[victim]) !== null && _a !== void 0 ? _a : 0;
        });
        return total;
    }
    static getAllKills(player) {
        var _a;
        const playerData = (_a = this.database.Tables.players.getEntry(player)) !== null && _a !== void 0 ? _a : { kills: {}, deaths: 0 };
        const returnData = { count: 0, kills: {} };
        for (const key in playerData.kills) {
            returnData.kills[key] = playerData.kills[key];
            returnData.count += playerData.kills[key];
        }
        return returnData;
    }
    static getAllKillsTotal() {
        const returnData = { count: 0, kills: {} };
        this.database.Tables.players.forEach((data, key) => {
            var _a;
            for (const key in data.kills) {
                returnData.kills[key] = ((_a = returnData.kills[key]) !== null && _a !== void 0 ? _a : 0) + data.kills[key];
                returnData.count += data.kills[key];
            }
        });
        return returnData;
    }
    static getDeaths(player) {
        var _a;
        const playerData = (_a = this.database.Tables.players.getEntry(player)) !== null && _a !== void 0 ? _a : { kills: {}, deaths: 0 };
        return playerData.deaths;
    }
    static getDeathsTotal() {
        let total = 0;
        this.database.Tables.players.forEach((data, key) => {
            total += data.deaths;
        });
        return total;
    }
}
DeathTally.database = new db.DataBase("player_kills", {
    tables: {
        players: {
            maxSize: Number.MAX_SAFE_INTEGER,
        }
    }
});
