/**
 * Optimized Logger utility
 * Reduces console.log noise in production while maintaining error tracking
 */
export class Logger {
  private static isDevelopment = process.env.NODE_ENV === 'development';
  private static isProduction = process.env.NODE_ENV === 'production';

  /**
   * Info level logging - only in development
   */
  static info(message: string, data?: any): void {
    if (this.isDevelopment) {
      console.log(`ℹ️ ${message}`, data || '');
    }
  }

  /**
   * Debug level logging - only in development
   */
  static debug(message: string, data?: any): void {
    if (this.isDevelopment) {
      console.log(`🐛 ${message}`, data || '');
    }
  }

  /**
   * Warning level logging - always logged
   */
  static warn(message: string, data?: any): void {
    console.warn(`⚠️ ${message}`, data || '');
  }

  /**
   * Error level logging - always logged
   */
  static error(message: string, error?: any): void {
    if (error && error.stack) {
      console.error(`❌ ${message}`, error.stack);
    } else {
      console.error(`❌ ${message}`, error || '');
    }
  }

  /**
   * Success level logging - only in development
   */
  static success(message: string, data?: any): void {
    if (this.isDevelopment) {
      console.log(`✅ ${message}`, data || '');
    }
  }

  /**
   * Performance logging for slow operations
   */
  static performance(operation: string, duration: number, threshold: number = 1000): void {
    if (duration > threshold) {
      console.warn(`🐌 Slow operation: ${operation} took ${duration}ms`);
    } else if (this.isDevelopment) {
      console.log(`⚡ ${operation} completed in ${duration}ms`);
    }
  }

  /**
   * Request logging middleware helper
   */
  static request(method: string, path: string, duration: number, statusCode: number): void {
    const emoji = statusCode >= 400 ? '❌' : statusCode >= 300 ? '⚠️' : '✅';

    if (this.isDevelopment || statusCode >= 400 || duration > 1000) {
      console.log(`${emoji} ${method} ${path} - ${statusCode} (${duration}ms)`);
    }
  }

  /**
   * Database operation logging
   */
  static db(operation: string, collection: string, duration?: number): void {
    if (this.isDevelopment && duration) {
      console.log(`🗄️ DB ${operation} on ${collection} (${duration}ms)`);
    }
  }
}