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

export default defineConfig({
  testDir: './e2e',
  globalSetup: './e2e/global-setup.ts',
  fullyParallel: false,
  forbidOnly: !!process.env.CI,
  retries: process.env.CI ? 2 : 0,
  workers: 1,
  reporter: 'html',
  timeout: 30000,

  use: {
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
  },

  projects: [
    {
      name: 'api',
      testMatch: [
        'api-health.spec.ts',
        'admin.spec.ts',
        'auth.spec.ts',
        'clients.spec.ts',
        'funnel.spec.ts',
        'rbac.spec.ts',
        'crm.spec.ts',
        'mvp-flow.spec.ts',
      ],
      use: {
        baseURL: process.env.E2E_API_URL || 'http://localhost:3000',
      },
    },
    {
      name: 'landing',
      testMatch: ['landing.spec.ts'],
      use: {
        ...devices['Desktop Chrome'],
        baseURL: process.env.E2E_LP_URL || 'http://localhost:3050',
      },
    },
    {
      name: 'web-admin',
      testMatch: ['web-admin-ui.spec.ts'],
      use: {
        ...devices['Desktop Chrome'],
        baseURL: process.env.E2E_WEB_ADMIN_URL || 'http://localhost:3001',
      },
    },
    {
      name: 'club-admin',
      testMatch: ['club-admin-ui.spec.ts'],
      use: {
        ...devices['Desktop Chrome'],
        baseURL: process.env.E2E_CLUB_ADMIN_URL || 'http://localhost:3002',
      },
    },
    {
      name: 'platform-admin',
      testMatch: ['platform-ui.spec.ts', 'mobile-layout.spec.ts'],
      use: {
        ...devices['Desktop Chrome'],
        baseURL: process.env.E2E_PLATFORM_ADMIN_URL || 'http://localhost:3003',
      },
    },
  ],
});
