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

/**
 * E2E harness. Track Q (docs/PRODUCT-PLAN-v3.1-DELIVERY-PLAN.md Q1) — none
 * existed before this. Runs against the mock-data build (environment.dev's
 * useMockData: true, per src/environments/), because the dev server this
 * session can reach has no live backend behind it.
 *
 * Once a real backend is reachable, point BASE_URL at it and set
 * PW_USE_MOCK_DATA=false to get end-to-end coverage instead of
 * frontend-only coverage. See e2e/README.md.
 */
export default defineConfig({
  testDir: './e2e',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 2 : undefined,
  reporter: process.env.CI ? [['github'], ['html', { open: 'never' }]] : 'list',

  use: {
    baseURL: process.env.BASE_URL ?? 'http://localhost:4200',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
  },

  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
  ],

  // Boots the mock-data dev server unless BASE_URL points somewhere already
  // running (a staging box, a locally-started server).
  webServer: process.env.BASE_URL
    ? undefined
    : {
        command: 'npm run dexar',
        url: 'http://localhost:4200',
        reuseExistingServer: !process.env.CI,
        timeout: 120_000,
      },
});
