import { readJson, writeJson, projectDataDir } from '../../storage/base-store.js';
import { randomUUID } from 'node:crypto';
function auditFile(projectId) {
    return `${projectDataDir(projectId)}/audit.json`;
}
/**
 * Append an audit entry. Returns the generated audit ID.
 * The audit trail is append-only — entries are never modified or removed.
 */
export async function appendAuditEntry(projectId, action, itemType, itemId, details) {
    const entries = await readJson(auditFile(projectId), []);
    const entry = {
        id: randomUUID(),
        timestamp: new Date().toISOString(),
        action,
        itemType,
        itemId,
        details,
    };
    entries.push(entry);
    await writeJson(auditFile(projectId), entries);
    return entry.id;
}
/**
 * Read all audit entries for a project.
 */
export async function getAuditEntries(projectId) {
    return readJson(auditFile(projectId), []);
}
//# sourceMappingURL=audit-logger.js.map