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

export const GetBlastRadiusInput = z.object({
  file_path: z.string().trim().min(1),
});
export type GetBlastRadiusInputT = z.infer<typeof GetBlastRadiusInput>;

const DESCRIPTION =
  'Returns all files that depend (transitively) on the given file, with depth tracking. ' +
  'Use to assess the impact of changing a file — "what breaks if I modify this?" ' +
  'Traverses the import graph in reverse via BFS. Results sorted by distance (closest dependents first).';

const { toolDef: getBlastRadius, execute: executeGetBlastRadius } =
  makeCodecontextTool<GetBlastRadiusInputT>({
    name: 'get_blast_radius',
    schema: GetBlastRadiusInput,
    description: DESCRIPTION,
    jsonParameters: {
      type: 'object',
      properties: {
        file_path: {
          type: 'string',
          description: 'Absolute or project-relative path to the file to analyze.',
        },
      },
      required: ['file_path'],
      additionalProperties: false,
    },
    mapArgs: (input) => ({ file_path: input.file_path }),
  });

export { getBlastRadius, executeGetBlastRadius };
