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

// Two browser projects per AC-18 (Chromium + Firefox). The runner runs from
// inside the suite-e2e docker-compose `playwright-runner` container; the
// `azaion-ui` service is reachable by container hostname.

const BASE_URL = process.env.PLAYWRIGHT_BASE_URL ?? 'http://azaion-ui:80'
const OUTPUT_DIR = process.env.PLAYWRIGHT_OUTPUT_DIR ?? './test-output/e2e'

export default defineConfig({
  testDir: './tests',
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 1 : 0,
  workers: 1,
  timeout: 60_000,
  expect: { timeout: 5_000 },
  reporter: [
    ['list'],
    ['junit', { outputFile: '../test-output/e2e-report.xml' }],
    ['html', { outputFolder: '../test-output/e2e-html', open: 'never' }],
  ],
  outputDir: OUTPUT_DIR,
  use: {
    baseURL: BASE_URL,
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },
  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
    { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
  ],
})
