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

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

const DESCRIPTION =
  'Returns detailed analysis of a single file: symbols defined, imports, exports, and inferred role. ' +
  'Use when you have a specific file in mind and need its structure without view_file-ing the whole thing. ' +
  'Tree-sitter coverage: full for JS/Python/Java/Go/Rust/C++. TypeScript symbols are approximate. ' +
  'PHP and SQL are not supported — fall back to view_file for those.';

const { toolDef: getFileAnalysis, execute: executeGetFileAnalysis } =
  makeCodecontextTool<GetFileAnalysisInputT>({
    name: 'get_file_analysis',
    schema: GetFileAnalysisInput,
    description: DESCRIPTION,
    jsonParameters: {
      type: 'object',
      properties: {
        file_path: {
          type: 'string',
          description: 'Absolute or project-relative path to the file.',
        },
      },
      required: ['file_path'],
      additionalProperties: false,
    },
    mapArgs: (input) => ({ file_path: input.file_path }),
  });

export { getFileAnalysis, executeGetFileAnalysis };
