/**
 * Centralized test utilities for Execution Engine tests
 * Provides mock creators for ExecutionContext and Tools
 */

import { vi } from 'vitest'
import type { Tool, ToolExecutionOptions } from '../tools/types'
import type { ExecutionContext } from '../base/types'
import { z } from 'zod'

/**
 * Create mock ExecutionContext for testing
 * Provides minimal required fields with sensible defaults
 *
 * @param overrides - Partial context to override defaults
 * @returns Complete ExecutionContext with all required fields
 */
export function createMockExecutionContext(overrides?: Partial<ExecutionContext>): ExecutionContext {
  return {
    executionId: 'test-exec-123',
    organizationId: 'test-org-123',
    organizationName: 'test-org',
    userId: 'test-user-123',
    resourceId: 'test-resource-123',
    executionDepth: 0,
    store: new Map(),
    logger: {
      info: vi.fn(),
      error: vi.fn(),
      warn: vi.fn(),
      debug: vi.fn()
    },
    ...overrides
  }
}

/**
 * Create mock tool for testing
 * Uses new ToolExecutionOptions signature
 *
 * @param name - Tool name
 * @param overrides - Partial tool definition to override
 * @returns Tool with mocked execute function
 */
export function createMockTool(name: string, overrides?: Partial<Tool>): Tool {
  return {
    name,
    description: `Mock tool: ${name}`,
    inputSchema: z.object({ input: z.string() }),
    outputSchema: z.object({ output: z.string() }),
    execute: vi.fn(async (options: ToolExecutionOptions) => ({
      output: `Result: ${(options.input as { input: string }).input}`
    })),
    ...overrides
  }
}
