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

export const GetHotFilesInput = z.object({
  limit: z.number().int().min(1).max(100).optional(),
});
export type GetHotFilesInputT = z.infer<typeof GetHotFilesInput>;

const DESCRIPTION =
  'Returns the most-imported files in the project, ranked by incoming import count. ' +
  'Hot files are high-risk change targets — many other files depend on them. ' +
  'Use to identify core modules and assess refactoring risk.';

const { toolDef: getHotFiles, execute: executeGetHotFiles } =
  makeCodecontextTool<GetHotFilesInputT>({
    name: 'get_hot_files',
    schema: GetHotFilesInput,
    description: DESCRIPTION,
    jsonParameters: {
      type: 'object',
      properties: {
        limit: {
          type: 'number',
          description: 'Maximum number of files to return (default 20, max 100).',
        },
      },
      additionalProperties: false,
    },
    mapArgs: (input) => (input.limit != null ? { limit: input.limit } : {}),
  });

export { getHotFiles, executeGetHotFiles };
