import type { z } from 'zod';
import type { Sql } from '../../db.js';

export interface ToolJsonSchema {
  type: 'function';
  function: {
    name: string;
    description: string;
    parameters: Record<string, unknown>;
  };
}

/**
 * Context passed to BooCoder tool execute functions.
 *
 * Unlike BooChat's tools (which only need projectRoot), BooCoder's write tools
 * interact with the database (pending_changes table) and need session/task
 * context for proper attribution.
 */
export interface ToolContext {
  sql: Sql;
  sessionId: string;
  taskId: string | null;
}

export interface ToolDef<TInput> {
  name: string;
  description: string;
  inputSchema: z.ZodType<TInput>;
  jsonSchema: ToolJsonSchema;
  execute(input: TInput, projectRoot: string, context: ToolContext): Promise<unknown>;
}
