import api from './index'

export interface KGNode {
  id: string
  name: string
  type: string
  description?: string
  importance: number
  created_at?: string
}

export interface KGEdge {
  id: string
  source: string
  target: string
  relation: string
  weight?: number
}

export interface GraphData {
  nodes: KGNode[]
  edges: KGEdge[]
  stats: {
    node_count: number
    edge_count: number
  }
}

export const graphApi = {
  get() {
    return api.get<GraphData>('/api/graph')
  },

  build() {
    return api.post('/api/graph/build')
  },

  getEntityContext(entity: string) {
    return api.get<{ context: string }>(`/api/graph/entity/${encodeURIComponent(entity)}`)
  },

  getSummary() {
    return api.get<{ summary: string }>('/api/graph/summary')
  },

  getNeighbors(nodeId: string, depth = 1) {
    return api.get<{ nodes: KGNode[]; edges: KGEdge[] }>(
      `/api/graph/neighbors/${nodeId}`,
      { params: { depth } }
    )
  },

  deleteNode(nodeId: string) {
    return api.delete(`/api/graph/nodes/${nodeId}`)
  },
}
