# Performance Testing Configuration
# mockupAWS v1.0.0

# Base configuration for all k6 tests
export const baseConfig = {
  // Base URL for the API
  baseUrl: __ENV.BASE_URL || 'http://localhost:8000',
  
  // Test phases
  phases: {
    smoke: {
      vus: 10,
      duration: '1m',
    },
    load: {
      stages100: [
        { duration: '2m', target: 100 },
        { duration: '5m', target: 100 },
        { duration: '2m', target: 0 },
      ],
      stages500: [
        { duration: '3m', target: 500 },
        { duration: '10m', target: 500 },
        { duration: '3m', target: 0 },
      ],
      stages1000: [
        { duration: '5m', target: 1000 },
        { duration: '15m', target: 1000 },
        { duration: '5m', target: 0 },
      ],
    },
    stress: {
      stages: [
        { duration: '2m', target: 100 },
        { duration: '2m', target: 250 },
        { duration: '2m', target: 500 },
        { duration: '2m', target: 750 },
        { duration: '2m', target: 1000 },
        { duration: '2m', target: 1500 },
        { duration: '2m', target: 2000 },
        { duration: '5m', target: 0 },
      ],
    },
  },
  
  // Performance thresholds (SLA requirements)
  thresholds: {
    http_req_duration: ['p(95)<200'],  // 95th percentile < 200ms
    http_req_duration: ['p(50)<100'],  // 50th percentile < 100ms  
    http_req_failed: ['rate<0.01'],     // Error rate < 1%
  },
  
  // User behavior simulation
  userBehavior: {
    minThinkTime: 1,  // Minimum seconds between requests
    maxThinkTime: 3,  // Maximum seconds between requests
  },
};

// Test data generators
export function generateTestData() {
  const timestamp = Date.now();
  const random = Math.floor(Math.random() * 100000);
  
  return {
    username: `loadtest_${random}_${timestamp}@test.com`,
    password: 'TestPassword123!',
    scenarioName: `LoadTest_Scenario_${random}`,
    scenarioDescription: 'Performance test scenario created by k6',
    tags: ['load-test', 'performance', 'k6'],
  };
}

// Helper to check response
export function checkResponse(response, checks) {
  const result = check(response, checks);
  return result;
}

// Metrics tags
export const tags = {
  smoke: { test_type: 'smoke' },
  load: { test_type: 'load' },
  stress: { test_type: 'stress' },
  benchmark: { test_type: 'benchmark' },
};
