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

/**
 * Single-container e2e setup — Mimic backend serves both /api/* and the built SPA.
 *
 * Sequence (run manually before `npx playwright test`):
 *   1. make build && make start
 *   2. make create-admin USER=root PASS=rootpass8
 *   3. ensure `curl /api/health` is 200
 *
 * Tests run **serially** because all state lives in a single SQLite file in the
 * shared container. RBAC tests need stable user fixtures across spec files.
 */
const baseURL = process.env.MIMIC_BASE_URL ?? 'http://localhost:5000';

export default defineConfig({
  testDir: './tests',
  fullyParallel: false,
  workers: 1,
  retries: process.env.CI ? 1 : 0,
  reporter: process.env.CI ? [['line'], ['html', { open: 'never' }]] : 'line',
  timeout: 30_000,
  expect: { timeout: 5_000 },
  use: {
    baseURL,
    headless: true,
    viewport: { width: 1280, height: 720 },
    screenshot: 'only-on-failure',
    trace: 'retain-on-failure',
    actionTimeout: 10_000,
    navigationTimeout: 15_000,
    extraHTTPHeaders: { 'Content-Type': 'application/json' },
  },
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
    },
  ],
});
