import Chart from "../core.js";
import { Users } from "../../../models/index.js";
import { Not, IsNull } from "typeorm";
import { name, schema } from "./entities/users.js";
/**
 * ユーザー数に関するチャート
 */ export default class UsersChart extends Chart {
    constructor(){
        super(name, schema);
    }
    async tickMajor() {
        const [localCount, remoteCount] = await Promise.all([
            Users.countBy({
                host: IsNull()
            }),
            Users.countBy({
                host: Not(IsNull())
            })
        ]);
        return {
            "local.total": localCount,
            "remote.total": remoteCount
        };
    }
    async tickMinor() {
        return {};
    }
    async update(user, isAdditional) {
        const prefix = Users.isLocalUser(user) ? "local" : "remote";
        await this.commit({
            [`${prefix}.total`]: isAdditional ? 1 : -1,
            [`${prefix}.inc`]: isAdditional ? 1 : 0,
            [`${prefix}.dec`]: isAdditional ? 0 : 1
        });
    }
}
