// storage/qa-gate-store.ts — SPEC-642
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { join, dirname } from 'node:path';
import { safeJsonParse } from './base-store.js';
function gatePath(projectPath, specId) {
    return join(projectPath, '.planu', 'qa-gate', `${specId}.json`);
}
export async function saveGateState(projectPath, specId, result) {
    const path = gatePath(projectPath, specId);
    await mkdir(dirname(path), { recursive: true });
    const state = { specId, lastResult: result };
    await writeFile(path, JSON.stringify(state, null, 2), 'utf-8');
}
export async function getGateState(projectPath, specId) {
    try {
        const raw = await readFile(gatePath(projectPath, specId), 'utf-8');
        const parsed = safeJsonParse(raw, null);
        return parsed && typeof parsed === 'object' && 'specId' in parsed ? parsed : null;
    }
    catch {
        return null;
    }
}
//# sourceMappingURL=qa-gate-store.js.map