// #region PlaywrightConfig [C:3] [TYPE Config] [SEMANTICS e2e, playwright, test, config]
// @BRIEF Playwright E2E test configuration for ss-tools frontend.
// @RELATION DEPENDS_ON -> [EXT:frontend:EnvConfig]]
// @INVARIANT All E2E tests run against a fully deployed stack (DB + backend + frontend).
// @UX_STATE ConfigLoaded -> Browser contexts are created with predefined env settings.

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

const BACKEND_URL = process.env.BACKEND_URL || 'http://127.0.0.1:8101';
const FRONTEND_URL = process.env.FRONTEND_URL || 'http://127.0.0.1:8102';
const AUTH_USERNAME = process.env.E2E_USERNAME || 'admin';
const AUTH_PASSWORD = process.env.E2E_PASSWORD || 'admin123';

export default defineConfig({
	testDir: './e2e/tests',
	testMatch: '**/*.e2e.js',
	fullyParallel: false,
	retries: process.env.CI ? 1 : 0,
	workers: 1, // sequential tests — settings mutate global state
	reporter: [
		['list'],
		['html', { outputFolder: 'playwright-report' }],
	],
	timeout: 60_000,
	expect: {
		timeout: 15_000,
	},
	use: {
		baseURL: FRONTEND_URL,
		trace: 'retain-on-failure',
		screenshot: 'only-on-failure',
		video: 'retain-on-failure',
	},
	projects: [
		{
			name: 'chromium',
			use: {
				...devices['Desktop Chrome'],
				viewport: { width: 1440, height: 900 },
			},
		},
	],
	// Global setup — runs once per worker
	globalSetup: './e2e/fixtures/global-setup.js',
	// Expose env vars to tests
	globalTeardown: undefined,
	// Share backend URL via env
	// Each test file can access process.env.BACKEND_URL
});

export { BACKEND_URL, FRONTEND_URL, AUTH_USERNAME, AUTH_PASSWORD };
// #endregion PlaywrightConfig
