import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
import { join, dirname } from 'node:path';
function getStatsPath(projectPath) {
    return join(projectPath, '.claude', 'reviews', 'stats.json');
}
export class FileSystemStatsGateway {
    loadProjectStats(projectPath) {
        const statsPath = getStatsPath(projectPath);
        if (!existsSync(statsPath)) {
            return null;
        }
        try {
            const content = readFileSync(statsPath, 'utf-8');
            const stats = JSON.parse(content);
            if (!Array.isArray(stats.reviews)) {
                stats.reviews = [];
            }
            return stats;
        }
        catch {
            return null;
        }
    }
    saveProjectStats(projectPath, stats) {
        const statsPath = getStatsPath(projectPath);
        const dir = dirname(statsPath);
        if (!existsSync(dir)) {
            mkdirSync(dir, { recursive: true });
        }
        stats.lastUpdated = new Date().toISOString();
        writeFileSync(statsPath, JSON.stringify(stats, null, 2), 'utf-8');
    }
    statsFileExists(projectPath) {
        return existsSync(getStatsPath(projectPath));
    }
}
//# sourceMappingURL=stats.fileSystem.js.map