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

export const GetFrameworkAnalysisInput = z.object({
  framework: z.string().optional(),
  include_stats: z.boolean().optional(),
});
export type GetFrameworkAnalysisInputT = z.infer<typeof GetFrameworkAnalysisInput>;

const DESCRIPTION =
  'Returns framework-specific structural analysis: component relationships (React), hook usage patterns, store wiring (Vue/Pinia), service registration (Angular/Nest), etc. ' +
  'When framework is omitted, codecontext auto-detects from the project files. ' +
  'Tree-sitter coverage: full for JS/Python/Java/Go/Rust/C++. TypeScript is approximate. ' +
  'PHP and SQL are not supported.';

const { toolDef: getFrameworkAnalysis, execute: executeGetFrameworkAnalysis } =
  makeCodecontextTool<GetFrameworkAnalysisInputT>({
    name: 'get_framework_analysis',
    schema: GetFrameworkAnalysisInput,
    description: DESCRIPTION,
    jsonParameters: {
      type: 'object',
      properties: {
        framework: {
          type: 'string',
          description: 'Framework name. Auto-detected if omitted.',
        },
        include_stats: {
          type: 'boolean',
          description: 'Include component/hook/service counts.',
        },
      },
      additionalProperties: false,
    },
    mapArgs: (input) => {
      const args: Record<string, unknown> = {};
      if (input.framework) args['framework'] = input.framework;
      if (input.include_stats !== undefined) args['include_stats'] = input.include_stats;
      return args;
    },
  });

export { getFrameworkAnalysis, executeGetFrameworkAnalysis };
