// storage/figma-store.ts — Figma integration persistence (SPEC-418)
import { join } from 'node:path';
import { hashProjectPath, readJson, writeJson } from './base-store.js';
import { withFileLock } from './file-mutex.js';
const MAX_SYNC_LOG_ENTRIES = 50;
function projectDir(projectPath) {
    const id = hashProjectPath(projectPath);
    return join('data', 'projects', id);
}
function configPath(projectPath) {
    return join(projectDir(projectPath), 'figma-config.json');
}
function syncLogPath(projectPath) {
    return join(projectDir(projectPath), 'figma-sync-log.json');
}
function generatedSpecsPath(projectPath) {
    return join(projectDir(projectPath), 'figma-generated-specs.json');
}
export async function getFigmaConfig(projectPath) {
    return readJson(configPath(projectPath), null);
}
export async function saveFigmaConfig(projectPath, config) {
    await writeJson(configPath(projectPath), config);
}
export async function getFigmaSyncLog(projectPath) {
    return readJson(syncLogPath(projectPath), []);
}
export async function appendFigmaSyncEntry(projectPath, entry) {
    const filePath = syncLogPath(projectPath);
    await withFileLock(filePath, async () => {
        const entries = await readJson(filePath, []);
        entries.push(entry);
        await writeJson(filePath, entries.slice(-MAX_SYNC_LOG_ENTRIES));
    });
}
export async function getFigmaGeneratedSpecs(projectPath) {
    return readJson(generatedSpecsPath(projectPath), []);
}
export async function saveFigmaGeneratedSpecs(projectPath, specs) {
    await writeJson(generatedSpecsPath(projectPath), specs);
}
function flowsPath(projectPath) {
    return join(projectDir(projectPath), 'figma-flows.json');
}
function snapshotPath(projectPath) {
    return join(projectDir(projectPath), 'figma-snapshot.json');
}
function tokensPath(projectPath) {
    return join(projectDir(projectPath), 'figma-tokens.json');
}
function webhookPath(projectPath) {
    return join(projectDir(projectPath), 'figma-webhook.json');
}
function codeConnectPath(projectPath) {
    return join(projectDir(projectPath), 'figma-code-connect.json');
}
function figmaFilesPath(projectPath) {
    return join(projectDir(projectPath), 'figma-files.json');
}
function versionsPath(projectPath) {
    return join(projectDir(projectPath), 'figma-versions.json');
}
function enrichmentPath(projectPath) {
    return join(projectDir(projectPath), 'figma-enrichment.json');
}
function visualQaPath(projectPath) {
    return join(projectDir(projectPath), 'figma-visual-qa.json');
}
export async function getFigmaFlows(projectPath) {
    return readJson(flowsPath(projectPath), []);
}
export async function saveFigmaFlows(projectPath, flows) {
    await writeJson(flowsPath(projectPath), flows);
}
export async function getFigmaSnapshot(projectPath) {
    return readJson(snapshotPath(projectPath), []);
}
export async function saveFigmaSnapshot(projectPath, snapshot) {
    await writeJson(snapshotPath(projectPath), snapshot);
}
export async function getFigmaTokens(projectPath) {
    return readJson(tokensPath(projectPath), []);
}
export async function saveFigmaTokens(projectPath, tokens) {
    await writeJson(tokensPath(projectPath), tokens);
}
export async function saveFigmaWebhook(projectPath, webhook) {
    await writeJson(webhookPath(projectPath), webhook);
}
export async function saveFigmaCodeConnect(projectPath, entries) {
    await writeJson(codeConnectPath(projectPath), entries);
}
export async function getFigmaCodeConnect(projectPath) {
    return readJson(codeConnectPath(projectPath), []);
}
export async function getFigmaFiles(projectPath) {
    return readJson(figmaFilesPath(projectPath), []);
}
export async function saveFigmaFiles(projectPath, files) {
    await writeJson(figmaFilesPath(projectPath), files);
}
export async function getFigmaVersions(projectPath) {
    return readJson(versionsPath(projectPath), {});
}
export async function saveFigmaVersions(projectPath, versions) {
    await writeJson(versionsPath(projectPath), versions);
}
export async function getFigmaEnrichment(projectPath) {
    return readJson(enrichmentPath(projectPath), []);
}
export async function saveFigmaEnrichment(projectPath, enrichment) {
    await writeJson(enrichmentPath(projectPath), enrichment);
}
export async function saveFigmaVisualQA(projectPath, results) {
    await writeJson(visualQaPath(projectPath), results);
}
//# sourceMappingURL=figma-store.js.map