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

export const GetCodebaseOverviewInput = z.object({
  include_stats: z.boolean().optional(),
});
export type GetCodebaseOverviewInputT = z.infer<typeof GetCodebaseOverviewInput>;

const DESCRIPTION =
  'Returns a structured overview of the codebase: file count, symbol count, primary languages, and top-level architecture. ' +
  'Use this before deeper investigation to orient yourself in an unfamiliar codebase. ' +
  'Tree-sitter coverage: full for JS/Python/Java/Go/Rust/C++. TypeScript symbols are approximate (uses JS grammar). ' +
  'PHP and SQL are not supported — fall back to view_file/grep for those.';

const { toolDef: getCodebaseOverview, execute: executeGetCodebaseOverview } =
  makeCodecontextTool<GetCodebaseOverviewInputT>({
    name: 'get_codebase_overview',
    schema: GetCodebaseOverviewInput,
    description: DESCRIPTION,
    jsonParameters: {
      type: 'object',
      properties: {
        include_stats: {
          type: 'boolean',
          description: 'Include file count, symbol count, language stats. Defaults to true.',
        },
      },
      additionalProperties: false,
    },
    mapArgs: (input) => ({ include_stats: input.include_stats ?? true }),
  });

export { getCodebaseOverview, executeGetCodebaseOverview };
