import { Logger } from "@core/shared/application";

export class ConsoleLogger implements Logger {
  private formatMessage(level: string, message: string, context?: unknown): string {
    const timestamp = new Date().toISOString();
    const contextStr = context ? ` | ${JSON.stringify(context)}` : '';
    return `[${timestamp}] ${level.toUpperCase()}: ${message}${contextStr}`;
  }

  debug(message: string, context?: unknown): void {
    console.debug(this.formatMessage('debug', message, context));
  }

  info(message: string, context?: unknown): void {
    console.info(this.formatMessage('info', message, context));
  }

  warn(message: string, context?: unknown): void {
    console.warn(this.formatMessage('warn', message, context));
  }

  error(message: string, error?: Error, context?: unknown): void {
    const errorStr = error ? ` | Error: ${error.message}` : '';
    console.error(this.formatMessage('error', message, context) + errorStr);
  }
}
