import { readJson, writeJson, hashProjectPath } from './base-store.js';
import { withFileLock } from './file-mutex.js';
function prLinksFile(projectPath) {
    const hash = hashProjectPath(projectPath);
    return `data/projects/${hash}/pr-links.json`;
}
/**
 * Load all PR links for a project.
 */
export async function getPrLinks(projectPath) {
    const file = prLinksFile(projectPath);
    return readJson(file, []);
}
/**
 * Save (append or update) a PR link for a project.
 * If a link with the same prUrl already exists, it is replaced.
 */
export async function savePrLink(projectPath, link) {
    const file = prLinksFile(projectPath);
    await withFileLock(file, async () => {
        const existing = await readJson(file, []);
        const idx = existing.findIndex((l) => l.prUrl === link.prUrl);
        if (idx !== -1) {
            existing[idx] = link;
        }
        else {
            existing.push(link);
        }
        await writeJson(file, existing);
    });
}
//# sourceMappingURL=pr-store.js.map