import { mkdirSync, writeFileSync, readdirSync, readFileSync, renameSync, existsSync } from 'fs';
import { join } from 'path';
import { homedir } from 'os';
export const ISSUE_QUEUE_DIR = join(homedir(), '.crosscheck', 'issues');
export function saveToIssueQueue(record) {
    mkdirSync(ISSUE_QUEUE_DIR, { recursive: true });
    const filename = `diagnose-${Date.now()}.json`;
    const filepath = join(ISSUE_QUEUE_DIR, filename);
    writeFileSync(filepath, JSON.stringify(record, null, 2));
    return filepath;
}
export function loadIssueQueue() {
    if (!existsSync(ISSUE_QUEUE_DIR))
        return [];
    const result = [];
    for (const f of readdirSync(ISSUE_QUEUE_DIR).sort()) {
        if (!f.endsWith('.json') || f.endsWith('.done.json'))
            continue;
        const filepath = join(ISSUE_QUEUE_DIR, f);
        try {
            const record = JSON.parse(readFileSync(filepath, 'utf8'));
            result.push({ path: filepath, record });
        }
        catch { /* skip malformed */ }
    }
    return result;
}
export function markQueueItemDone(filepath) {
    const donePath = filepath.replace(/\.json$/, '.done.json');
    try {
        renameSync(filepath, donePath);
    }
    catch { /* ignore */ }
}
//# sourceMappingURL=issue-queue.js.map