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

export default defineConfig({
  testDir: './e2e',
  fullyParallel: true,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: 'html',
  use: {
    baseURL: 'http://127.0.0.1:3103',
    trace: 'on-first-retry',
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
  webServer: {
    command: 'pnpm exec next dev --webpack --hostname 127.0.0.1 --port 3103',
    url: 'http://127.0.0.1:3103',
    reuseExistingServer: process.env.E2E_REUSE_SERVER === '1',
    timeout: 60_000,
    // Provide the env vars /api/health requires so the health gate is deterministic.
    // These are non-secret placeholders only used to exercise the health handler.
    env: {
      PLATFORM_API_URL: 'http://localhost:4003',
      JWT_SECRET: 'e2e-placeholder-not-a-real-secret',
      DEFAULT_PRODUCT_ID: 'tracker-e2e',
    },
  },
});
