/**
 * Custom logger utility
 * Provides structured logging with environment-aware output
 */

type LogLevel = "debug" | "info" | "warn" | "error"

interface LogMetadata {
  [key: string]: any
}

class Logger {
  private isDev =
    typeof process !== "undefined" &&
    process.env.NODE_ENV === "development"

  /**
   * Internal log method
   */
  private log(level: LogLevel, prefix: string, message: string, metadata?: LogMetadata) {
    const timestamp = new Date().toISOString()
    const logPrefix = `[${timestamp}] [${prefix}]`

    if (level === "error") {
      console.error(logPrefix, message, metadata || "")
    } else if (level === "warn") {
      console.warn(logPrefix, message, metadata || "")
    } else if (this.isDev || level === "info") {
      // Info messages show in production too
      // eslint-disable-next-line no-console
      console.log(logPrefix, message, metadata || "")
    }
  }

  /**
   * Debug level - development only
   */
  debug(prefix: string, message: string, metadata?: LogMetadata) {
    this.log("debug", prefix, message, metadata)
  }

  /**
   * Info level - always visible
   */
  info(prefix: string, message: string, metadata?: LogMetadata) {
    this.log("info", prefix, message, metadata)
  }

  /**
   * Warning level
   */
  warn(prefix: string, message: string, metadata?: LogMetadata) {
    this.log("warn", prefix, message, metadata)
  }

  /**
   * Error level
   */
  error(prefix: string, message: string, metadata?: LogMetadata) {
    this.log("error", prefix, message, metadata)
  }
}

export const logger = new Logger()






