// storage/spec-lint-rules-store.ts — Persists custom lint rules (SPEC-364)
// Layout: data/projects/{hash}/lint-rules.json
import { readJson, writeJson, projectDataDir, hashProjectPath } from './base-store.js';
function lintRulesFile(projectId) {
    return `${projectDataDir(projectId)}/lint-rules.json`;
}
const DEFAULT_DATA = { rules: [], updatedAt: new Date().toISOString() };
export async function loadLintRules(projectPath) {
    const projectId = hashProjectPath(projectPath);
    const data = await readJson(lintRulesFile(projectId), DEFAULT_DATA);
    return data.rules;
}
export async function saveLintRule(projectPath, rule) {
    const projectId = hashProjectPath(projectPath);
    const filePath = lintRulesFile(projectId);
    const data = await readJson(filePath, DEFAULT_DATA);
    const idx = data.rules.findIndex((r) => r.id === rule.id);
    if (idx >= 0) {
        data.rules[idx] = rule;
    }
    else {
        data.rules.push(rule);
    }
    data.updatedAt = new Date().toISOString();
    await writeJson(filePath, data);
}
export async function deleteLintRule(projectPath, ruleId) {
    const projectId = hashProjectPath(projectPath);
    const filePath = lintRulesFile(projectId);
    const data = await readJson(filePath, DEFAULT_DATA);
    const before = data.rules.length;
    data.rules = data.rules.filter((r) => r.id !== ruleId);
    if (data.rules.length === before) {
        return false;
    }
    data.updatedAt = new Date().toISOString();
    await writeJson(filePath, data);
    return true;
}
//# sourceMappingURL=spec-lint-rules-store.js.map