import { defineConfig } from '@playwright/test'
import jwt from 'jsonwebtoken'

const port = 18788
const adminToken = jwt.sign({ sub: 'e2e-admin', role: 'admin', name: 'Player' }, 'osint-e2e-jwt-secret')

export default defineConfig({
  testDir: './e2e',
  fullyParallel: false,
  workers: 1,
  retries: 0,
  timeout: 30_000,
  use: {
    baseURL: `http://127.0.0.1:${port}`,
    headless: true,
    viewport: { width: 1280, height: 720 },
    extraHTTPHeaders: { Cookie: `auth_token=${adminToken}` },
  },
  webServer: {
    command: 'npm run e2e:serve',
    url: `http://127.0.0.1:${port}/api/health`,
    reuseExistingServer: false,
    timeout: 120_000,
    gracefulShutdown: { signal: 'SIGTERM', timeout: 10_000 },
  },
})
