import { Injectable } from '@angular/core';

/**
 * Centralized logging service for the application.
 * In production, logs are disabled by default to prevent information leakage.
 */
@Injectable({
  providedIn: 'root'
})
export class LoggerService {
  private isProduction = false;
  private isDebugEnabled = false;

  constructor() {
    // Check if we're in production mode
    this.isProduction = !window.location.hostname.includes('localhost') && 
                       !window.location.hostname.includes('127.0.0.1');
    
    // Enable debug logging in development or if explicitly enabled
    this.isDebugEnabled = !this.isProduction || 
                         localStorage.getItem('DEBUG_LOGGING') === 'true';
  }

  /**
   * Log debug information (only in development)
   */
  debug(message: string, ...args: any[]): void {
    if (this.isDebugEnabled) {
      console.debug(`[DEBUG] ${message}`, ...args);
    }
  }

  /**
   * Log informational messages
   */
  info(message: string, ...args: any[]): void {
    if (this.isDebugEnabled) {
      console.info(`[INFO] ${message}`, ...args);
    }
  }

  /**
   * Log warnings (always logged)
   */
  warn(message: string, ...args: any[]): void {
    console.warn(`[WARN] ${message}`, ...args);
  }

  /**
   * Log errors (always logged)
   */
  error(message: string, error?: any, ...args: any[]): void {
    if (error) {
      console.error(`[ERROR] ${message}`, error, ...args);
    } else {
      console.error(`[ERROR] ${message}`, ...args);
    }
  }

  /**
   * Log in production (for critical errors only)
   */
  log(message: string, ...args: any[]): void {
    if (this.isDebugEnabled) {
      console.log(`[LOG] ${message}`, ...args);
    }
  }
}

