// storage/time-tracking-store.ts — SPEC-404: Time tracking persistence
import { join } from 'node:path';
import { readJson, writeJson, projectDataDir } from './base-store.js';
import { withFileLock } from './file-mutex.js';
function trackingFile(projectId) {
    return join(projectDataDir(projectId), 'time-tracking.json');
}
export async function getTimeRecord(projectId, specId) {
    const data = await readJson(trackingFile(projectId), {});
    return data[specId] ?? null;
}
export async function saveTimeRecord(projectId, record) {
    return withFileLock(trackingFile(projectId), async () => {
        const data = await readJson(trackingFile(projectId), {});
        data[record.specId] = record;
        await writeJson(trackingFile(projectId), data);
        return record;
    });
}
export async function updateTimeRecord(projectId, specId, updates) {
    return withFileLock(trackingFile(projectId), async () => {
        const data = await readJson(trackingFile(projectId), {});
        const existing = data[specId] ?? { specId };
        const updated = { ...existing, ...updates, specId };
        data[specId] = updated;
        await writeJson(trackingFile(projectId), data);
        return updated;
    });
}
export async function listTimeRecords(projectId) {
    const data = await readJson(trackingFile(projectId), {});
    return Object.values(data);
}
//# sourceMappingURL=time-tracking-store.js.map