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

export const WatchChangesInput = z.object({
  enable: z.boolean(),
});
export type WatchChangesInputT = z.infer<typeof WatchChangesInput>;

const DESCRIPTION =
  "Turn codecontext's file watcher on or off for this project. " +
  'When on, codecontext re-analyzes files in the background as they change (debounced). Default is on. ' +
  "Disable temporarily if you're doing bulk edits and want to avoid analysis churn.";

const { toolDef: watchChanges, execute: executeWatchChanges } =
  makeCodecontextTool<WatchChangesInputT>({
    name: 'watch_changes',
    schema: WatchChangesInput,
    description: DESCRIPTION,
    jsonParameters: {
      type: 'object',
      properties: {
        enable: {
          type: 'boolean',
          description: 'true = enable the watcher; false = disable.',
        },
      },
      required: ['enable'],
      additionalProperties: false,
    },
    mapArgs: (input) => ({ enable: input.enable }),
  });

export { watchChanges, executeWatchChanges };
