export class SummarizeTokenUsageUseCase {
    gateway;
    constructor(gateway) {
        this.gateway = gateway;
    }
    async execute({ localPath, since }) {
        const allRecords = await this.gateway.loadAll(localPath);
        const records = since
            ? allRecords.filter(record => record.recordedAt >= since)
            : allRecords;
        const summary = {
            totalInputTokens: 0,
            totalOutputTokens: 0,
            totalCacheRead: 0,
            totalCacheCreation: 0,
            totalCostUsd: 0,
            recordCount: records.length,
            byModel: {},
        };
        for (const record of records) {
            summary.totalInputTokens += record.usage.inputTokens;
            summary.totalOutputTokens += record.usage.outputTokens;
            summary.totalCacheRead += record.usage.cacheReadInputTokens;
            summary.totalCacheCreation += record.usage.cacheCreationInputTokens;
            summary.totalCostUsd += record.usage.costUsd;
            const modelEntry = summary.byModel[record.model];
            if (modelEntry) {
                modelEntry.count += 1;
                modelEntry.costUsd += record.usage.costUsd;
            }
            else {
                summary.byModel[record.model] = { count: 1, costUsd: record.usage.costUsd };
            }
        }
        return summary;
    }
}
//# sourceMappingURL=summarizeTokenUsage.usecase.js.map