import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests/e2e',
  timeout: 180_000,  // WASM 부팅 시간 포함 (최대 ~120초)
  expect: {
    timeout: 90_000
  },
  fullyParallel: !!process.env.CI,
  forbidOnly: !!process.env.CI,
  retries: 0,
  reporter: process.env.CI ? [['list'], ['html', { open: 'never' }]] : 'list',
  use: {
    // Green-Blue 배포 지원:
    // - 로컬 Nginx: http://localhost (포트 무관, active 버전 자동 라우팅)
    // - 원격: https://www.taxbaik.com (또는 process.env.E2E_BASE_URL)
    // - CI: 환경변수로 명시적 설정 가능
    baseURL: process.env.E2E_BASE_URL ?? 'http://localhost',
    trace: 'retain-on-failure',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure'
  },
  projects: [
    {
      name: 'Desktop Chrome',
      use: { ...devices['Desktop Chrome'] }
    },
    {
      name: 'iPhone 12',
      use: { ...devices['iPhone 12'] }
    },
    {
      name: 'iPad Pro',
      use: { ...devices['iPad Pro'] }
    },
    {
      name: 'Galaxy S9+',
      use: { ...devices['Galaxy S9+'] }
    },
    {
      name: 'Public Smoke',
      testMatch: /public-smoke\.spec\.ts$/,
      use: { ...devices['Desktop Chrome'] }
    },
    {
      name: 'Admin Smoke',
      testMatch: /admin-smoke\.spec\.ts$/,
      use: { ...devices['Desktop Chrome'] }
    },
    {
      name: 'Route Isolation',
      testMatch: /route-isolation\.spec\.ts$/,
      use: { ...devices['Desktop Chrome'] }
    }
  ]
});
