/**
 * AI驱动测试自动化配置
 * 
 * @module testing/config/test-automation.config
 * @version 1.0.0
 */

import type { MCPConfig } from '../tools/types';

/**
 * 测试自动化配置
 */
export const testAutomationConfig = {
  /**
   * MCP配置
   */
  mcp: {
    command: 'npx',
    args: [
      '@playwright/mcp@latest',
      '--browser=chromium',
      '--headless',
      '--save-trace',
      '--save-video=1280x720',
      '--save-session',
      '--test-id-attribute=data-testid',
    ],
  } as MCPConfig,

  /**
   * 执行配置
   */
  execution: {
    // 默认浏览器
    defaultBrowser: 'chromium' as const,
    // 默认环境
    defaultEnvironment: 'test' as const,
    // 默认超时（毫秒）
    defaultTimeout: 30000,
    // 默认重试次数
    defaultRetryCount: 3,
    // 默认并行度
    defaultParallel: 1,
    // 开发环境并行度
    devParallel: 1,
    // CI环境并行度
    ciParallel: 4,
  },

  /**
   * 环境配置
   */
  environments: {
    development: {
      baseUrl: 'http://localhost:3000',
      apiUrl: 'http://localhost:4000',
    },
    test: {
      baseUrl: 'https://test.ff.com',
      apiUrl: 'https://test-api.ff.com',
    },
    staging: {
      baseUrl: 'https://staging.ff.com',
      apiUrl: 'https://staging-api.ff.com',
    },
    production: {
      baseUrl: 'https://ff.com',
      apiUrl: 'https://api.ff.com',
    },
  },

  /**
   * 鉴权配置
   */
  auth: {
    storageStateDir: './testing/.auth',
    accounts: {
      admin: {
        username: 'test_admin@ff.com',
        password: process.env.TEST_ADMIN_PASSWORD || 'Admin@2024',
        storageState: 'admin.json',
      },
      manager: {
        username: 'test_manager@ff.com',
        password: process.env.TEST_MANAGER_PASSWORD || 'Manager@2024',
        storageState: 'manager.json',
      },
      employee: {
        username: 'test_employee@ff.com',
        password: process.env.TEST_EMPLOYEE_PASSWORD || 'Employee@2024',
        storageState: 'employee.json',
      },
    },
  },

  /**
   * 报告配置
   */
  reporting: {
    outputDir: './test',
    screenshotOnFailure: true,
    videoOnFailure: true,
    traceOnFailure: true,
    keepSuccessArtifacts: false,
    reportFormat: ['markdown', 'json'] as const,
  },

  /**
   * AI分析配置
   */
  aiAnalysis: {
    enabled: true,
    confidenceThreshold: 0.7,
    autoFixLevel1: true,
    autoFixLevel2: false,
    autoFixLevel3: false,
  },

  /**
   * 回归测试配置
   */
  regression: {
    // 策略选择
    strategySelection: {
      level1: 'minimal' as const,
      level2: 'module' as const,
      level3: 'full' as const,
    },
    // 自动触发
    autoTrigger: true,
    // 并行度
    parallel: {
      minimal: 1,
      module: 2,
      dependency: 3,
      full: 4,
    },
  },

  /**
   * 文档同步配置
   */
  documentSync: {
    enabled: true,
    autoUpdate: false,
    checkBeforeTest: true,
    checkAfterFix: true,
  },

  /**
   * 性能目标
   */
  performance: {
    pageLoadTarget: 2000, // 2秒
    apiResponseTarget: 500, // 500ms
    testDurationTarget: 60000, // 60秒
  },

  /**
   * 覆盖率目标
   */
  coverage: {
    p0PassRateTarget: 95, // 95%
    overallPassRateTarget: 90, // 90%
  },

  /**
   * 通知配置
   */
  notifications: {
    enabled: false,
    channels: {
      email: {
        enabled: false,
        recipients: [],
      },
      slack: {
        enabled: false,
        webhookUrl: process.env.SLACK_WEBHOOK_URL,
      },
      webhook: {
        enabled: false,
        url: process.env.WEBHOOK_URL,
      },
    },
  },
};

export default testAutomationConfig;
