import { readJson, writeJson, hashProjectPath } from './base-store.js';
import { withFileLock } from './file-mutex.js';
function surfacesFile(projectPath) {
    const hash = hashProjectPath(projectPath);
    return `data/projects/${hash}/api-surfaces.json`;
}
/** Load all API surfaces for a project. */
export async function loadApiSurfaces(projectPath) {
    return readJson(surfacesFile(projectPath), []);
}
/** Register (upsert) API surfaces for a spec. */
export async function saveApiSurface(projectPath, surface) {
    const file = surfacesFile(projectPath);
    await withFileLock(file, async () => {
        const existing = await readJson(file, []);
        const idx = existing.findIndex((s) => s.specId === surface.specId);
        if (idx === -1) {
            existing.push(surface);
        }
        else {
            existing[idx] = surface;
        }
        await writeJson(file, existing);
    });
}
/** Load API surface for a single spec. */
export async function loadApiSurfaceForSpec(projectPath, specId) {
    const all = await loadApiSurfaces(projectPath);
    return all.find((s) => s.specId === specId) ?? null;
}
//# sourceMappingURL=api-surfaces-store.js.map