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

const testTimeout = Number(process.env.E2E_TEST_TIMEOUT || '120000');
const navigationTimeout = Number(process.env.E2E_NAVIGATION_TIMEOUT || '60000');

/**
 * Playwright E2E Test Configuration
 * Target: MBInventario Symfony 2.x Application
 */
export default defineConfig({
  testDir: './tests/e2e',
  timeout: testTimeout,
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: 1,
  reportSlowTests: null,
  reporter: 'html',
  use: {
    baseURL: process.env.BASE_URL || 'http://localhost/mbinv/web/',
    navigationTimeout,
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },

  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'], channel: 'chrome' },
    },
  ],

  webServer: {
    command: 'echo "Ensure web server is running on http://localhost/mbinv/web/"',
    url: process.env.BASE_URL || 'http://localhost/mbinv/web/',
    reuseExistingServer: !process.env.CI,
    timeout: 120000,
  },
});
