// storage/slack-store.ts — Slack integration persistence (SPEC-292)
import { join } from 'node:path';
import { hashProjectPath, readJson, writeJson } from './base-store.js';
import { withFileLock } from './file-mutex.js';
// ---------------------------------------------------------------------------
// Path helpers
// ---------------------------------------------------------------------------
const MAX_DELIVERIES = 20;
function getProjectDir(projectPath) {
    const hash = hashProjectPath(projectPath);
    return join('data', 'projects', hash);
}
function getConfigPath(projectPath) {
    return join(getProjectDir(projectPath), 'slack-config.json');
}
function getDeliveryLogPath(projectPath) {
    return join(getProjectDir(projectPath), 'slack-deliveries.json');
}
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/**
 * Read the Slack config for a project. Returns null if not configured.
 */
export async function getSlackConfig(projectPath) {
    const config = await readJson(getConfigPath(projectPath), null);
    return config;
}
/**
 * Persist the Slack config for a project.
 */
export async function saveSlackConfig(projectPath, config) {
    await writeJson(getConfigPath(projectPath), config);
}
/**
 * Remove the Slack config for a project.
 */
export async function removeSlackConfig(projectPath) {
    await writeJson(getConfigPath(projectPath), null);
}
/**
 * Read the last N delivery log entries for a project.
 */
export async function getDeliveryLog(projectPath) {
    const entries = await readJson(getDeliveryLogPath(projectPath), []);
    return entries.slice(-MAX_DELIVERIES);
}
/**
 * Append a delivery record to the log (keeps last 20).
 */
export async function appendDelivery(projectPath, delivery) {
    const deliveryLogPath = getDeliveryLogPath(projectPath);
    await withFileLock(deliveryLogPath, async () => {
        const existing = await readJson(deliveryLogPath, []);
        const updated = [...existing, delivery].slice(-MAX_DELIVERIES);
        await writeJson(deliveryLogPath, updated);
    });
}
//# sourceMappingURL=slack-store.js.map