// SPEC-452 — TDD Policy persistence
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { join } from 'node:path';
import { safeJsonParse } from './base-store.js';
const DATA_DIR = 'data/projects';
const FILE_NAME = 'tdd-policy.json';
const DEFAULT_POLICY = {
    mode: 'soft',
    coverageThreshold: 80,
    requireEdgeTests: false,
};
export async function getTddPolicy(projectId) {
    const filePath = join(DATA_DIR, projectId, FILE_NAME);
    try {
        const raw = await readFile(filePath, 'utf-8');
        return { ...DEFAULT_POLICY, ...safeJsonParse(raw, {}) };
    }
    catch {
        return { ...DEFAULT_POLICY };
    }
}
export async function saveTddPolicy(projectId, policy) {
    const dir = join(DATA_DIR, projectId);
    await mkdir(dir, { recursive: true });
    await writeFile(join(dir, FILE_NAME), JSON.stringify(policy, null, 2), 'utf-8');
}
//# sourceMappingURL=tdd-policy-store.js.map