import Chart from "../core.js";
import { DriveFiles } from "../../../models/index.js";
import { name, schema } from "./entities/per-user-drive.js";
/**
 * ユーザーごとのドライブに関するチャート
 */ export default class PerUserDriveChart extends Chart {
    constructor(){
        super(name, schema, true);
    }
    async tickMajor(group) {
        const [count, size] = await Promise.all([
            DriveFiles.countBy({
                userId: group
            }),
            DriveFiles.calcDriveUsageOf(group)
        ]);
        return {
            totalCount: count,
            totalSize: size
        };
    }
    async tickMinor() {
        return {};
    }
    async update(file, isAdditional) {
        const fileSizeKb = file.size / 1000;
        await this.commit({
            totalCount: isAdditional ? 1 : -1,
            totalSize: isAdditional ? fileSizeKb : -fileSizeKb,
            incCount: isAdditional ? 1 : 0,
            incSize: isAdditional ? fileSizeKb : 0,
            decCount: isAdditional ? 0 : 1,
            decSize: isAdditional ? 0 : fileSizeKb
        }, file.userId);
    }
}
