/**
 * Knowledge graph node/edge factory functions.
 */

import {
  type GraphNode,
  type NodeId,
  type SourceLocation,
  NodeType,
} from "../types";

export function makeNodeId(
  filePath: string,
  name: string,
  nodeType: NodeType,
): NodeId {
  return `${nodeType}:${filePath}:${name}`;
}

export function makeFileNode(
  filePath: string,
  pkg: string,
  loc: number,
): GraphNode {
  return {
    id: makeNodeId(filePath, filePath, NodeType.FILE),
    type: NodeType.FILE,
    name: filePath,
    location: { filePath, lineStart: 1, lineEnd: loc } satisfies SourceLocation,
    attributes: { package: pkg, loc },
  };
}

export function makePackageNode(pkg: string): GraphNode {
  return {
    id: `package:${pkg}`,
    type: NodeType.PACKAGE,
    name: pkg,
    attributes: {},
  };
}
