/**
 * Staging Environment Configuration for HVAC Testing Framework
 * 
 * Configuration specific to the staging environment at upskill-staging.measurequick.com
 * 
 * @package HVAC_Community_Events
 * @version 2.0.0
 * @created 2025-08-27
 */

module.exports = {
    // Application Settings
    app: {
        baseUrl: 'https://upskill-staging.measurequick.com',
        environment: 'staging',
        debug: true
    },
    
    // Test User Configurations
    environments: {
        users: {
            trainer: {
                username: 'test_trainer',
                email: 'test_trainer@example.com',
                password: 'TestTrainer123!',
                role: 'hvac_trainer',
                defaultPage: '/trainer/dashboard/'
            },
            masterTrainer: {
                username: 'test_master',
                email: 'test_master@example.com',
                password: 'TestMaster123!',
                role: 'hvac_master_trainer',
                defaultPage: '/master-trainer/master-dashboard/'
            },
            admin: {
                username: 'admin',
                email: 'admin@upskill-staging.measurequick.com',
                password: process.env.STAGING_ADMIN_PASSWORD || 'AdminPassword123!',
                role: 'administrator',
                defaultPage: '/wp-admin/'
            },
            // Alternative master trainer account
            masterTrainerAlt: {
                username: 'JoeMedosch@gmail.com',
                email: 'JoeMedosch@gmail.com',
                password: 'JoeTrainer2025@',
                role: 'hvac_master_trainer',
                defaultPage: '/master-trainer/master-dashboard/'
            }
        }
    },
    
    // Database Configuration (for direct access if needed)
    database: {
        host: process.env.STAGING_DB_HOST || 'localhost',
        name: process.env.STAGING_DB_NAME || 'upskill_staging',
        user: process.env.STAGING_DB_USER || 'staging_user',
        password: process.env.STAGING_DB_PASSWORD || '',
        prefix: 'wp_',
        charset: 'utf8mb4',
        isolation: true // Use transactions for test isolation
    },
    
    // WordPress-specific settings
    wordpress: {
        cliPath: 'wp',
        adminPath: '/wp-admin/',
        loginPath: '/wp-login.php',
        customLoginPath: '/training-login/',
        apiPath: '/wp-json/',
        databaseIsolation: false, // Don't modify staging database
        flushRewriteRules: false,  // Don't flush rules on staging
        clearCache: false          // Don't clear cache on staging
    },
    
    // Browser settings optimized for staging
    browser: {
        headless: process.env.CI === 'true' || process.env.HEADLESS === 'true',
        slowMo: process.env.CI === 'true' ? 0 : 200,
        viewport: {
            width: 1280,
            height: 720
        },
        args: [
            '--disable-dev-shm-usage',
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--ignore-certificate-errors', // For staging SSL
            '--ignore-ssl-errors',
            '--disable-web-security'
        ]
    },
    
    // Test execution parameters
    framework: {
        timeout: 45000,    // Longer timeout for staging
        retries: 3,        // More retries for staging network issues
        parallel: true,
        maxWorkers: 2,     // Fewer workers for staging
        testDataIsolation: false, // Don't modify staging data
        screenshotsOnFailure: true,
        videosOnFailure: true
    },
    
    // Staging-specific test data
    testData: {
        seedData: false,        // Don't seed data on staging
        cleanupAfterTests: false, // Don't cleanup staging data
        isolateTransactions: false,
        backupDatabase: false,
        fixtures: {
            users: './fixtures/staging-users.json',
            events: './fixtures/staging-events.json',
            venues: './fixtures/staging-venues.json'
        }
    },
    
    // Features available in staging
    features: {
        trainerRegistration: true,
        eventCreation: true,
        profileManagement: true,
        announcements: true,
        masterTrainerTools: true,
        importExport: true,
        communicationTemplates: true,
        trainingLeads: true,
        certificates: true,
        geocoding: true,
        mobileResponsive: true
    },
    
    // Staging-specific selectors (may differ from production)
    selectors: {
        dataTestIdAttribute: 'data-testid',
        roleAttribute: 'data-role',
        pageAttribute: 'data-page',
        formAttribute: 'data-form',
        buttonAttribute: 'data-action'
    },
    
    // Media settings for staging
    media: {
        screenshotDir: './test-results/screenshots/staging',
        videoDir: './test-results/videos/staging',
        screenshotMode: 'only-on-failure',
        videoMode: 'retain-on-failure',
        quality: 80,
        fullPage: false
    },
    
    // Reporting configuration
    reporting: {
        outputDir: './test-results/reports/staging',
        formats: ['html', 'json'],
        includeScreenshots: true,
        includeTimings: true,
        groupByCategory: true,
        stagingSpecificMetadata: {
            environment: 'staging',
            baseUrl: 'https://upskill-staging.measurequick.com',
            testRunId: process.env.TEST_RUN_ID || Date.now().toString()
        }
    },
    
    // Network and security settings for staging
    network: {
        timeout: 30000,
        ignoreHTTPSErrors: true,
        bypassCSP: false,
        userAgent: 'HVAC-Testing-Framework/2.0 Playwright (Staging)'
    },
    
    // Expected staging-specific URLs and endpoints
    urls: {
        login: '/training-login/',
        wpLogin: '/wp-login.php',
        trainerDashboard: '/trainer/dashboard/',
        masterDashboard: '/master-trainer/master-dashboard/',
        createEvent: '/trainer/create-event/',
        manageEvents: '/trainer/events/',
        profile: '/trainer/profile/',
        findTrainer: '/find-trainer/',
        registration: '/trainer-registration/'
    },
    
    // Expected staging content and messages
    expectedContent: {
        loginPageTitle: 'Training Login',
        dashboardTitle: 'HVAC Trainer Dashboard',
        masterDashboardTitle: 'Master Trainer Dashboard',
        welcomeMessage: 'Welcome to HVAC Training',
        noAccessMessage: 'You do not have permission to access this page'
    },
    
    // Known staging issues or workarounds
    stagingSpecific: {
        // SSL certificate issues
        ignoreSSLErrors: true,
        
        // Known slow endpoints
        slowEndpoints: [
            '/master-trainer/events/',
            '/trainer/create-event/',
            '/find-trainer/'
        ],
        
        // Features that might be unstable
        unstableFeatures: [
            'geocoding',
            'csv-import'
        ],
        
        // Cache behavior
        cacheEnabled: true,
        cacheTTL: 3600
    }
};