// src/services/logger.client.ts
/**
 * A simple, client-side logger service that wraps the console.
 * This version is guaranteed to be safe for browser environments as it
 * does not reference any Node.js-specific globals like `process`.
 */

// Export the logger object for use throughout the client-side application.
/**
 * A simple, client-side logger that mimics the pino API for structured logging.
 * It supports signatures like `logger.info('message')` and `logger.info({ data }, 'message')`.
 */
export const logger = {
  info: (objOrMsg: Record<string, unknown> | string, ...args: unknown[]) => {
    if (typeof objOrMsg === 'string') {
      console.log(`[INFO] ${objOrMsg}`, ...args);
    } else {
      console.log(`[INFO] ${args[0] || ''}`, objOrMsg, ...args.slice(1));
    }
  },
  warn: (objOrMsg: Record<string, unknown> | string, ...args: unknown[]) => {
    if (typeof objOrMsg === 'string') {
      console.warn(`[WARN] ${objOrMsg}`, ...args);
    } else {
      console.warn(`[WARN] ${args[0] || ''}`, objOrMsg, ...args.slice(1));
    }
  },
  error: (objOrMsg: Record<string, unknown> | string, ...args: unknown[]) => {
    if (typeof objOrMsg === 'string') {
      console.error(`[ERROR] ${objOrMsg}`, ...args);
    } else {
      console.error(`[ERROR] ${args[0] || ''}`, objOrMsg, ...args.slice(1));
    }
  },
  debug: (objOrMsg: Record<string, unknown> | string, ...args: unknown[]) => {
    if (typeof objOrMsg === 'string') {
      console.debug(`[DEBUG] ${objOrMsg}`, ...args);
    } else {
      console.debug(`[DEBUG] ${args[0] || ''}`, objOrMsg, ...args.slice(1));
    }
  },
};