import { Injectable, LoggerService as NestLoggerService } from '@nestjs/common';
import { winstonLogger } from '../config/winston.config';

/**
 * 自定义 Logger 服务
 * 集成 Winston 和 NestJS Logger 接口
 */
@Injectable()
export class LoggerService implements NestLoggerService {
  private context?: string;

  constructor(context?: string) {
    this.context = context;
  }

  setContext(context: string) {
    this.context = context;
  }

  log(message: any, context?: string) {
    const ctx = context || this.context;
    winstonLogger.info(message, { context: ctx });
  }

  error(message: any, trace?: string, context?: string) {
    const ctx = context || this.context;
    winstonLogger.error(message, { context: ctx, stack: trace });
  }

  warn(message: any, context?: string) {
    const ctx = context || this.context;
    winstonLogger.warn(message, { context: ctx });
  }

  debug(message: any, context?: string) {
    const ctx = context || this.context;
    winstonLogger.debug(message, { context: ctx });
  }

  verbose(message: any, context?: string) {
    const ctx = context || this.context;
    winstonLogger.verbose(message, { context: ctx });
  }
}

