import { z } from 'zod';
import { makeCodecontextTool } from './factory.js';

export const GetCallGraphInput = z.object({
  symbol: z.string().describe('Symbol name to analyze'),
  depth: z.number().int().min(1).max(5).optional().describe('Max traversal depth (default 2)'),
});
export type GetCallGraphInputT = z.infer<typeof GetCallGraphInput>;

const DESCRIPTION =
  'Returns a call graph for a function or method: callers, callees, and transitive references. ' +
  'Use to understand how a symbol is invoked and what it depends on.';

const { toolDef: getCallGraph, execute: executeGetCallGraph } =
  makeCodecontextTool<GetCallGraphInputT>({
    name: 'get_call_graph',
    schema: GetCallGraphInput,
    description: DESCRIPTION,
    jsonParameters: {
      type: 'object',
      properties: {
        symbol: { type: 'string', description: 'Symbol name to analyze' },
        depth: { type: 'number', description: 'Max traversal depth (default 2)' },
      },
      required: ['symbol'],
      additionalProperties: false,
    },
    mapArgs: (input) => ({ symbol: input.symbol, depth: input.depth ?? 2 }),
  });

export { getCallGraph, executeGetCallGraph };
