/**
 * Browser mode configuration module for headed/headless browser toggle.
 *
 * Determines browser mode based on NODE_ENV:
 * - development: default headed, but configurable via runtime setter
 * - production: always headless
 * - test: always headless
 * - default: headless (for safety)
 */

export type BrowserMode = 'headed' | 'headless';

export interface BrowserModeConfig {
  mode: BrowserMode;
  source: 'GUI' | 'NODE_ENV';
}

/**
 * Loader for browser mode configuration.
 * Determines whether browser should run in headed or headless mode based on NODE_ENV.
 * In development mode, provides runtime control via setter method.
 */
export class BrowserModeConfigLoader {
  private developmentMode: BrowserMode = 'headless'; // Default to headless in development

  /**
   * Load browser mode configuration based on NODE_ENV.
   * - NODE_ENV=development: returns current developmentMode (default: headed)
   * - NODE_ENV=production: always headless
   * - NODE_ENV=test: always headless
   * - default: headless (for safety)
   */
  load(): BrowserModeConfig {
    const nodeEnv = process.env.NODE_ENV || 'production';
    
    if (nodeEnv === 'development') {
      return { mode: this.developmentMode, source: 'GUI' };
    }
    
    return { mode: 'headless', source: 'NODE_ENV' };
  }

  /**
   * Set browser mode for development environment.
   * Only affects behavior when NODE_ENV=development.
   * @param mode - The browser mode to use in development
   */
  setDevelopmentMode(mode: BrowserMode): void {
    this.developmentMode = mode;
  }

  /**
   * Get current development browser mode setting.
   * @returns The current browser mode for development
   */
  getDevelopmentMode(): BrowserMode {
    return this.developmentMode;
  }
}