import { z } from 'zod'
import type { AgentDefinition } from '../../agent/core/types'
import type { KnowledgeMap } from '../../agent/knowledge-map/types'
import { createApprovalTool } from '../../tools/platform/approval/tool'

/**
 * Create test agent with platform tools
 */
export function createPlatformToolAgent(): AgentDefinition {
  return {
    config: {
      resourceId: 'platform-tool-agent',
      name: 'Platform Tool Agent',
      description: 'Test agent with platform tools for approval workflows',
      systemPrompt: 'You help with approvals and notifications',
      type: 'agent',
      kind: 'utility',
      status: 'dev',
      version: '1.0.0'
    },
    contract: {
      inputSchema: z.object({ task: z.string() }),
      outputSchema: z.object({ status: z.string(), taskId: z.string().optional() })
    },
    tools: [
      createApprovalTool({
        name: 'request_approval',
        description: 'Request approval',
        inputSchema: z.object({ amount: z.number() }),
        outputSchema: z.object({ taskId: z.string() }),
        approveTargetResourceId: 'payment-processor'
      })
    ],
    modelConfig: { provider: 'mock', model: 'mock', apiKey: 'test-api-key' }
  }
}

/**
 * Create test knowledge map with mock nodes
 */
export function createTestKnowledgeMap(): KnowledgeMap {
  return {
    nodes: {
      'test-tools': {
        id: 'test-tools',
        description: 'Test tool set for validation',
        load: async (_context) => ({
          prompt: '# Test Tools\n\nYou have access to test tools.',
          tools: [
            {
              name: 'test_tool_1',
              description: 'Test tool 1',
              inputSchema: z.object({ input: z.string() }),
              outputSchema: z.object({ output: z.string() }),
              execute: async ({ input }) => ({ output: `Result: ${(input as { input: string }).input}` })
            }
          ]
        })
      }
    }
  }
}

/**
 * Create test agent with knowledge map
 */
export function createKnowledgeMapAgent(): AgentDefinition {
  return {
    config: {
      resourceId: 'knowledge-agent',
      name: 'Knowledge Map Agent',
      description: 'Test agent with knowledge map for dynamic capability loading',
      systemPrompt: 'You can load knowledge nodes as needed',
      type: 'agent',
      kind: 'utility',
      status: 'dev',
      version: '1.0.0'
    },
    contract: {
      inputSchema: z.object({ task: z.string() }),
      outputSchema: z.object({ result: z.string() })
    },
    tools: [],
    knowledgeMap: createTestKnowledgeMap(),
    modelConfig: { provider: 'mock', model: 'mock', apiKey: 'test-api-key' }
  }
}
