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

const AUTH_FILE = 'e2e/.auth/session.json'

export default defineConfig({
  testDir: './e2e',
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: 1,
  reporter: 'html',
  timeout: 30_000,

  use: {
    baseURL: process.env.E2E_BASE_URL || 'http://localhost:3001',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
  },

  projects: [
    // Auth setup: selects a profile to get a session cookie
    {
      name: 'auth-setup',
      testMatch: /auth\.setup\.ts/,
    },

    // All tests run after auth setup, with the saved session
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
        storageState: AUTH_FILE,
      },
      dependencies: ['auth-setup'],
    },
  ],
})
