"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.logger = exports.logUser = exports.logSession = exports.logPerformance = exports.logPayment = exports.logError = exports.logDevice = exports.logAuth = exports.logApi = exports.LogLevel = void 0;
/**
 * Centralized logging utilities for consistent logging across the application
 */
let LogLevel = exports.LogLevel = /*#__PURE__*/function (LogLevel) {
  LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
  LogLevel[LogLevel["INFO"] = 1] = "INFO";
  LogLevel[LogLevel["WARN"] = 2] = "WARN";
  LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
  LogLevel[LogLevel["NONE"] = 4] = "NONE";
  return LogLevel;
}({});
class Logger {
  level = LogLevel.INFO;
  isDevelopment = process.env.NODE_ENV === 'development';
  setLevel(level) {
    this.level = level;
  }
  shouldLog(level) {
    return level >= this.level;
  }
  formatMessage(level, message, context) {
    const timestamp = new Date().toISOString();
    const contextStr = context ? ` [${Object.entries(context).map(([k, v]) => `${k}:${v}`).join(', ')}]` : '';
    return `[${timestamp}] ${level}${contextStr}: ${message}`;
  }
  debug(message, context, ...args) {
    if (this.shouldLog(LogLevel.DEBUG)) {
      const formattedMessage = this.formatMessage('DEBUG', message, context);
      if (this.isDevelopment) {
        console.log(formattedMessage, ...args);
      }
    }
  }
  info(message, context, ...args) {
    if (this.shouldLog(LogLevel.INFO)) {
      const formattedMessage = this.formatMessage('INFO', message, context);
      console.log(formattedMessage, ...args);
    }
  }
  warn(message, context, ...args) {
    if (this.shouldLog(LogLevel.WARN)) {
      const formattedMessage = this.formatMessage('WARN', message, context);
      console.warn(formattedMessage, ...args);
    }
  }
  error(message, error, context, ...args) {
    if (this.shouldLog(LogLevel.ERROR)) {
      const formattedMessage = this.formatMessage('ERROR', message, context);
      if (error) {
        console.error(formattedMessage, error, ...args);
      } else {
        console.error(formattedMessage, ...args);
      }
    }
  }

  // Specialized logging methods for common patterns
  auth(message, context, ...args) {
    this.info(`🔐 ${message}`, {
      ...context,
      category: 'auth'
    }, ...args);
  }
  api(message, context, ...args) {
    this.info(`🌐 ${message}`, {
      ...context,
      category: 'api'
    }, ...args);
  }
  session(message, context, ...args) {
    this.info(`📱 ${message}`, {
      ...context,
      category: 'session'
    }, ...args);
  }
  user(message, context, ...args) {
    this.info(`👤 ${message}`, {
      ...context,
      category: 'user'
    }, ...args);
  }
  device(message, context, ...args) {
    this.info(`📱 ${message}`, {
      ...context,
      category: 'device'
    }, ...args);
  }
  payment(message, context, ...args) {
    this.info(`💳 ${message}`, {
      ...context,
      category: 'payment'
    }, ...args);
  }

  // Performance logging
  performance(operation, duration, context) {
    const level = duration > 1000 ? LogLevel.WARN : LogLevel.INFO;
    const message = `⏱️ ${operation} completed in ${duration}ms`;
    if (level === LogLevel.WARN) {
      this.warn(message, {
        ...context,
        category: 'performance',
        duration
      });
    } else {
      this.info(message, {
        ...context,
        category: 'performance',
        duration
      });
    }
  }

  // Error logging with stack trace
  errorWithStack(message, error, context) {
    this.error(message, error, {
      ...context,
      stack: error.stack
    });
  }

  // Group related log messages
  group(label, fn) {
    if (this.isDevelopment && this.shouldLog(LogLevel.DEBUG)) {
      console.group(label);
      fn();
      console.groupEnd();
    } else {
      fn();
    }
  }
}

// Create singleton instance
const logger = exports.logger = new Logger();

// Convenience functions for common logging patterns
const logAuth = (message, context, ...args) => logger.auth(message, context, ...args);
exports.logAuth = logAuth;
const logApi = (message, context, ...args) => logger.api(message, context, ...args);
exports.logApi = logApi;
const logSession = (message, context, ...args) => logger.session(message, context, ...args);
exports.logSession = logSession;
const logUser = (message, context, ...args) => logger.user(message, context, ...args);
exports.logUser = logUser;
const logDevice = (message, context, ...args) => logger.device(message, context, ...args);
exports.logDevice = logDevice;
const logPayment = (message, context, ...args) => logger.payment(message, context, ...args);
exports.logPayment = logPayment;
const logError = (message, error, context, ...args) => logger.error(message, error, context, ...args);
exports.logError = logError;
const logPerformance = (operation, duration, context) => logger.performance(operation, duration, context);
exports.logPerformance = logPerformance;
//# sourceMappingURL=loggerUtils.js.map