// storage/release-notes-store.ts — SPEC-438: Persistence for release notes config
import { readFile, writeFile, mkdir } from 'node:fs/promises';
import { join, dirname } from 'node:path';
import { createHash } from 'node:crypto';
import { safeJsonParse } from './base-store.js';
function hashProjectPath(p) {
    return createHash('sha256').update(p).digest('hex').slice(0, 16);
}
function configFile(projectPath) {
    const hash = hashProjectPath(projectPath);
    return join('data', 'projects', hash, 'release-notes-config.json');
}
/**
 * Load the release notes config for a project.
 * Returns null when no config has been saved yet.
 */
export async function getReleaseNotesConfig(projectPath) {
    const file = configFile(projectPath);
    try {
        const raw = await readFile(file, 'utf-8');
        return safeJsonParse(raw, null);
    }
    catch (err) {
        if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {
            return null;
        }
        throw err;
    }
}
/**
 * Persist the release notes config for a project.
 */
export async function saveReleaseNotesConfig(projectPath, config) {
    const file = configFile(projectPath);
    await mkdir(dirname(file), { recursive: true });
    await writeFile(file, JSON.stringify(config, null, 2), 'utf-8');
}
//# sourceMappingURL=release-notes-store.js.map