import { format } from "../date/format";

/**
 * Simple logger con niveles y timestamps.
 */
export class Logger {
  constructor(private context?: string) {}

  private timestamp(): string {
    return format(new Date(), "YYYY-MM-DD HH:mm:ss");
  }

  info(message: unknown, ...optional: unknown[]): void {
    console.info(
      `${this.timestamp()} [INFO]${
        this.context ? " [" + this.context + "]" : ""
      } -`,
      message,
      ...optional
    );
  }

  warn(message: unknown, ...optional: unknown[]): void {
    console.warn(
      `${this.timestamp()} [WARN]${
        this.context ? " [" + this.context + "]" : ""
      } -`,
      message,
      ...optional
    );
  }

  error(message: unknown, ...optional: unknown[]): void {
    console.error(
      `${this.timestamp()} [ERROR]${
        this.context ? " [" + this.context + "]" : ""
      } -`,
      message,
      ...optional
    );
  }

  debug(message: unknown, ...optional: unknown[]): void {
    if (process.env.DEBUG === "true") {
      console.debug(
        `${this.timestamp()} [DEBUG]${
          this.context ? " [" + this.context + "]" : ""
        } -`,
        message,
        ...optional
      );
    }
  }
}
