/**
 * @module utils/logger
 * @description Utilities for logging messages to the console with formatting
 */

import chalk from "chalk";
import { Logger } from "../types/index.js";

/**
 * Creates a logger for a specific module with colored console output
 *
 * @param module - The module name to use as prefix in log messages
 * @returns A logger object with methods for different log levels
 *
 * @example
 * ```typescript
 * const logger = createLogger('my-module');
 * logger.info('Starting process...');
 * logger.success('Process completed!');
 * logger.warn('Something might be wrong');
 * logger.error('Something went wrong');
 * ```
 */
export function createLogger(module: string): Logger {
  const prefix = `[${module}]`;

  return {
    /**
     * Log an info message with blue prefix
     * @param message - The message to log
     */
    info: (message: string): void => {
      console.log(`${chalk.blue(prefix)} ${message}`);
    },

    /**
     * Log a success message with green prefix and checkmark
     * @param message - The message to log
     */
    success: (message: string): void => {
      console.log(`${chalk.green(prefix)} ${chalk.green("✓")} ${message}`);
    },

    /**
     * Log a warning message with yellow prefix and warning symbol
     * @param message - The message to log
     */
    warn: (message: string): void => {
      console.log(`${chalk.yellow(prefix)} ${chalk.yellow("⚠")} ${message}`);
    },

    /**
     * Log an error message with red prefix and error symbol
     * @param message - The message to log
     */
    error: (message: string): void => {
      console.error(`${chalk.red(prefix)} ${chalk.red("✗")} ${message}`);
    },
  };
}
