/**
 * Playwright Global Setup
 * 
 * Runs once before all tests to prepare the test environment.
 */

import { FullConfig } from '@playwright/test';
import { setupAuthStates } from '../fixtures/auth';
import { cleanupTestData } from '../fixtures/database';

async function globalSetup(config: FullConfig) {
  console.log('🚀 Starting global setup...');

  try {
    // Clean up any leftover test data from previous runs
    console.log('🧹 Cleaning up leftover test data...');
    await cleanupTestData();

    // Setup authentication states for all user roles
    console.log('🔐 Setting up authentication states...');
    await setupAuthStates(config);

    console.log('✅ Global setup complete');
  } catch (error) {
    console.error('❌ Global setup failed:', error);
    throw error;
  }
}

export default globalSetup;
