import { defineConfig, devices } from '@playwright/test';
import { config as dotenvConfig } from 'dotenv';
import path from 'path';
import { VerbosityController, VerbosityLevel, parseVerbosityArgs } from './tests/e2e/utils/VerbosityController';
import { createCustomReporter } from './tests/e2e/reporters/reporterFactory';

// Load environment variables
dotenvConfig();

// Set minimal verbosity
const verbosity = VerbosityController.getInstance();
verbosity.setLevel(VerbosityLevel.MINIMAL);

// Staging server configuration
export const STAGING_CONFIG = {
    url: 'wordpress-974670-5399585.cloudwaysapps.com',
    ip: '146.190.76.204',
    sshUser: 'roodev',
    path: '/home/974670.cloudwaysapps.com/uberrxmprk/public_html'
} as const;

export default defineConfig({
    testDir: './tests/e2e',
    timeout: 30000,
    fullyParallel: true,
    forbidOnly: !!process.env.CI,
    retries: process.env.CI ? 2 : 0,
    workers: process.env.CI ? 1 : undefined,
    
    // Minimal reporting configuration
    reporter: [
        ['dot'], // Most minimal reporter - just shows dots for passes and brief failure messages
    ],

    // Global test configuration
    use: {
        baseURL: `https://${STAGING_CONFIG.url}`,
        trace: 'retain-on-failure',
        
        // Screenshot configuration based on verbosity
        screenshot: {
            mode: 'only-on-failure',
            fullPage: true
        },
        
        // Video configuration based on verbosity
        video: {
            mode: 'retain-on-failure',
            size: { width: 1280, height: 720 }
        },
        
        // Minimal logging configuration
        contextOptions: {
            logger: {
                isEnabled: (name, severity) => severity === 'error', // Only enable error logging
                log: (name, severity, message) => {
                    if (severity === 'error') {
                        console.error(`[${name}] ${message}`);
                    }
                }
            }
        }
    },

    // Test projects configuration
    // REDUCED: Only run tests on Chromium desktop for faster, focused CI.
    projects: [
        {
            name: 'chromium',
            use: {
                ...devices['Desktop Chrome'],
                viewport: { width: 1920, height: 1080 }
            },
        }
    ],

    // Global setup configuration
    globalSetup: require.resolve('./tests/e2e/global-setup'),
    globalTeardown: require.resolve('./tests/e2e/global-teardown'),
});
