// storage/force-analytics-store.ts — Track forceStatus and forceApprove usage per project (SPEC-969)
import { readJson, writeJson, projectDataDir } from './base-store.js';
import { join } from 'node:path';
function analyticsPath(projectId) {
    return join(projectDataDir(projectId), 'force-analytics.json');
}
export async function readForceAnalytics(projectId) {
    const defaultValue = {
        forcedTransitions: [],
        stats: { totalSpecs: 0, forcedSpecs: 0, ratio: 0 },
    };
    return readJson(analyticsPath(projectId), defaultValue);
}
export async function writeForceAnalytics(projectId, analytics) {
    await writeJson(analyticsPath(projectId), analytics);
}
export async function recordForceUsage(projectId, entry, totalSpecs) {
    const analytics = await readForceAnalytics(projectId);
    analytics.forcedTransitions.push({
        ...entry,
        timestamp: new Date().toISOString(),
    });
    // De-duplicate forced specs by specId
    const uniqueForcedSpecs = new Set(analytics.forcedTransitions.map((t) => t.specId));
    analytics.stats = {
        totalSpecs,
        forcedSpecs: uniqueForcedSpecs.size,
        ratio: totalSpecs > 0 ? uniqueForcedSpecs.size / totalSpecs : 0,
    };
    await writeForceAnalytics(projectId, analytics);
    return analytics;
}
//# sourceMappingURL=force-analytics-store.js.map