// ============================================================================
// Playwright · baseline QA · OTO Enterprise OS DTP
// ----------------------------------------------------------------------------
// Cible configurable via DTP_BASE_URL (aucune URL codée en dur → run local,
// VPS interne, ou domaine public selon l'environnement du runner).
//   export DTP_BASE_URL=https://otov7.com          # public
//   export DTP_BASE_URL=http://153.75.250.214      # VPS interne
// Voir tests/README.md.
// ============================================================================
import { defineConfig, devices } from '@playwright/test';

const BASE_URL = process.env.DTP_BASE_URL ?? 'https://otov7.com';
const IS_CI = !!process.env.CI;

export default defineConfig({
  testDir: './e2e',
  fullyParallel: true,
  forbidOnly: IS_CI,
  retries: IS_CI ? 1 : 0,
  workers: IS_CI ? 2 : undefined,
  timeout: 45_000,
  expect: { timeout: 10_000 },

  reporter: [
    ['list'],
    ['html', { outputFolder: 'playwright-report', open: 'never' }],
    ['junit', { outputFile: 'test-results/junit.xml' }],
  ],

  use: {
    baseURL: BASE_URL,
    navigationTimeout: 30_000,
    actionTimeout: 10_000,
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
    ignoreHTTPSErrors: true, // certificats internes VPS tolérés
  },

  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
    // Majorité des acheteurs sur mobile (spec CHOISIR_MON_UNITE).
    { name: 'mobile-safari', use: { ...devices['iPhone 14'] } },
  ],
});
