/** Simple log-level utility.
 *
 * Default level is `info`, which suppresses `debug` output.
 * Set to `debug` (via config or `setLevel()`) to see all messages.
 */

export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';

const LEVELS: Record<LogLevel, number> = {
  debug: 0,
  info: 1,
  warn: 2,
  error: 3,
  silent: 4,
};

let currentLevel: LogLevel = 'info';

export function setLogLevel(level: LogLevel): void {
  currentLevel = level;
}

export function getLogLevel(): LogLevel {
  return currentLevel;
}

function shouldLog(level: LogLevel): boolean {
  return LEVELS[level] >= LEVELS[currentLevel];
}

export const logger = {
  debug(...args: unknown[]): void {
    if (shouldLog('debug')) {console.debug(...args);}
  },
  info(...args: unknown[]): void {
    if (shouldLog('info')) {console.log(...args);}
  },
  warn(...args: unknown[]): void {
    if (shouldLog('warn')) {console.warn(...args);}
  },
  error(...args: unknown[]): void {
    if (shouldLog('error')) {console.error(...args);}
  },
};
