import { mapCandidateRow, mapEdgeRow, mapExtractionRow, mapIssueRow, mapJobRunRow, mapNodeRow, mapRefinementTaskRow, mapReportRow, mapScheduleRow, mapSourceRow, mapUsageRow, } from './store-schema.js';
function loadRows(sqlite, sql, mapRow) {
    const rows = sqlite.exec(sql);
    if (!rows.length)
        return [];
    return (rows[0]?.values ?? []).map((row) => mapRow(rows[0]?.columns ?? [], row));
}
export function loadKnowledgeStoreSnapshot(sqlite) {
    return {
        sources: loadRows(sqlite, 'SELECT * FROM knowledge_sources', mapSourceRow),
        nodes: loadRows(sqlite, 'SELECT * FROM knowledge_nodes', mapNodeRow),
        edges: loadRows(sqlite, 'SELECT * FROM knowledge_edges', mapEdgeRow),
        issues: loadRows(sqlite, 'SELECT * FROM knowledge_issues', mapIssueRow),
        extractions: loadRows(sqlite, 'SELECT * FROM knowledge_extractions', mapExtractionRow),
        jobRuns: loadRows(sqlite, 'SELECT * FROM knowledge_job_runs', mapJobRunRow),
        refinementTasks: loadRows(sqlite, 'SELECT * FROM knowledge_refinement_tasks', mapRefinementTaskRow),
        usageRecords: loadRows(sqlite, 'SELECT * FROM knowledge_usage_records', mapUsageRow),
        consolidationCandidates: loadRows(sqlite, 'SELECT * FROM knowledge_consolidation_candidates', mapCandidateRow),
        consolidationReports: loadRows(sqlite, 'SELECT * FROM knowledge_consolidation_reports', mapReportRow),
        schedules: loadRows(sqlite, 'SELECT * FROM knowledge_schedules', mapScheduleRow),
    };
}
