// storage/spec-bindings-store.ts — Spec bindings persistence (SPEC-349)
// Layout: data/projects/{hash}/spec-bindings.json
import { readJson, writeJson, projectDataDir, hashProjectPath } from './base-store.js';
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
function dataFile(projectPath) {
    const projectId = hashProjectPath(projectPath);
    return `${projectDataDir(projectId)}/spec-bindings.json`;
}
// ---------------------------------------------------------------------------
// Store functions
// ---------------------------------------------------------------------------
export async function getAllBindings(projectPath) {
    return readJson(dataFile(projectPath), []);
}
export async function saveAllBindings(projectPath, bindings) {
    await writeJson(dataFile(projectPath), bindings);
}
export async function getBinding(projectPath, id) {
    const bindings = await getAllBindings(projectPath);
    return bindings.find((b) => b.id === id) ?? null;
}
export async function upsertBinding(projectPath, binding) {
    const bindings = await getAllBindings(projectPath);
    const idx = bindings.findIndex((b) => b.id === binding.id);
    if (idx >= 0) {
        bindings[idx] = binding;
    }
    else {
        bindings.push(binding);
    }
    await saveAllBindings(projectPath, bindings);
}
export async function removeBinding(projectPath, id) {
    const bindings = await getAllBindings(projectPath);
    const filtered = bindings.filter((b) => b.id !== id);
    await saveAllBindings(projectPath, filtered);
}
export async function getBindingsForSpec(projectPath, specId) {
    const bindings = await getAllBindings(projectPath);
    return bindings.filter((b) => b.specId === specId);
}
//# sourceMappingURL=spec-bindings-store.js.map