class GraphExporter {
  store;
  graph;
  constructor(store, graph) {
    this.store = store;
    this.graph = graph;
  }
  exportAsJSON(repo, filesFilter) {
    let files = this.store.getAllFiles(repo);
    let symbols = this.store.getAllSymbols(repo);
    let edges = this.store.getAllEdges(repo);
    if (filesFilter) {
      const allowed = new Set(filesFilter);
      files = files.filter((f) => allowed.has(f.path));
      symbols = symbols.filter((s) => allowed.has(s.file_path));
      edges = edges.filter((e) => allowed.has(e.source_file) && allowed.has(e.target_file));
    }
    const graphData = this.graph.toJSON();
    if (filesFilter) {
      const allowed = new Set(filesFilter);
      graphData.nodes = graphData.nodes.filter((n) => allowed.has(n.key));
      graphData.edges = graphData.edges.filter((e) => allowed.has(e.source) && allowed.has(e.target));
    }
    const clusters = this.store.getClusters(repo);
    const memberships = this.store.getClusterMemberships(repo);
    return {
      version: "1.0.0",
      exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
      repo: repo || "all",
      summary: {
        totalFiles: files.length,
        totalSymbols: symbols.length,
        totalEdges: edges.length,
        languages: this.store.getLanguageBreakdown(repo),
        totalClusters: clusters.length
      },
      files: files.map((f) => ({
        path: f.path,
        language: f.language,
        sizeBytes: f.size_bytes,
        lines: f.lines,
        lastScanned: f.last_scanned,
        metadata: f.metadata ? JSON.parse(f.metadata) : void 0
      })),
      symbols: symbols.map((s) => ({
        name: s.name,
        kind: s.kind,
        scope: s.scope || void 0,
        signature: s.signature,
        file: s.file_path,
        line: s.start_line,
        endLine: s.end_line
      })),
      edges: edges.map((e) => ({
        source: e.source_file,
        target: e.target_file,
        type: e.edge_type,
        sourceSymbol: e.source_symbol || void 0,
        targetSymbol: e.target_symbol || void 0,
        verifiability: e.verifiability || "verified",
        metadata: e.metadata ? JSON.parse(e.metadata) : void 0
      })),
      clusters: clusters.map((c) => ({
        name: c.name,
        label: c.label,
        source: c.source,
        parentName: c.parent_name || void 0,
        depth: c.depth,
        fileCount: c.file_count
      })),
      memberships: memberships.map((m) => ({
        filePath: m.file_path,
        clusterName: m.cluster_name,
        isPrimary: m.is_primary === 1
      })),
      graph: graphData
    };
  }
  exportAsJSONString(repo, filesFilter) {
    return JSON.stringify(this.exportAsJSON(repo, filesFilter), null, 2);
  }
}
export {
  GraphExporter
};
