import r from '@/utils/request'
import { getRequestId } from '@/utils/misc'
import { serverRequest,type RequestBody, type StandardResponse } from '@/api/AgentApi'

const URL_GET_NODE = '/api/kb/nodes'
const URL_GET_SUMMARY = '/api/kb/summary'
const URL_GET_SCHEMA = '/api/kb/schemas'
export function searchNodes(keyword:string, graph_id:number): Promise<StandardResponse> {
    var data:RequestBody = {
        id: getRequestId(),
        action: 'search_nodes', 
        params:[
            {name: 'name', value: keyword} ,
            {name: 'category', value: "any"} ,
            {name: 'graph_id', value: graph_id},
        ]
    }
    return serverRequest(URL_GET_NODE, data)
}

export function getNodeNeighbors(node_id:number, graph_id:number): Promise<StandardResponse> {
    var data:RequestBody = {
        id: getRequestId(),
        action:'neighbors',
        params:[
            {name: 'node_id', value: node_id},
            {name: 'graph_id', value: graph_id},
        ]
    } 
    return serverRequest(URL_GET_NODE, data)
}
export function getGraphSummary(params:any): Promise<StandardResponse> {
    console.log(params)
    var data:RequestBody = {
        id: getRequestId(),
        action: 'get_summary',
        params:[
            {name: 'graph_id', value: params['graph_id']},      
        ] 
    }
    return serverRequest(URL_GET_SUMMARY, data)
}

export function getGraphNodeSchema(params:any): Promise<StandardResponse> {
    console.log(params)
    var data:RequestBody = {
        id: getRequestId(),
        action: 'get_nodes_schemas',
        params:[
            {name: 'graph_id', value: params['graph_id']},
        ]
    } 
    return serverRequest(URL_GET_SCHEMA, data)
}


export function getGraphEdgeSchema(params:any): Promise<StandardResponse> {
    console.log(params)
    var data:RequestBody = {
        id: getRequestId(),
        action: 'get_edges_schemas',
        params:[
            {name: 'graph_id', value: params['graph_id']},
        ]
    } 
    return serverRequest(URL_GET_SCHEMA, data)
}