"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = exports.Logger = exports.LogLevel = void 0;
var LogLevel;
(function (LogLevel) {
    LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
    LogLevel[LogLevel["INFO"] = 1] = "INFO";
    LogLevel[LogLevel["WARN"] = 2] = "WARN";
    LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
})(LogLevel || (exports.LogLevel = LogLevel = {}));
class Logger {
    constructor() {
        this.logLevel = LogLevel.INFO;
        const envLogLevel = process.env.LOG_LEVEL?.toUpperCase();
        if (envLogLevel && envLogLevel in LogLevel) {
            this.logLevel = LogLevel[envLogLevel];
        }
    }
    static getInstance() {
        if (!Logger.instance) {
            Logger.instance = new Logger();
        }
        return Logger.instance;
    }
    formatMessage(level, message, context) {
        const timestamp = new Date().toISOString();
        const contextStr = context ? `[${context}]` : '';
        return `${timestamp} [${level}]${contextStr} ${message}`;
    }
    log(level, levelName, message, context) {
        if (level >= this.logLevel) {
            // eslint-disable-next-line no-console
            console.log(this.formatMessage(levelName, message, context));
        }
    }
    debug(message, context) {
        this.log(LogLevel.DEBUG, 'DEBUG', message, context);
    }
    info(message, context) {
        this.log(LogLevel.INFO, 'INFO', message, context);
    }
    warn(message, context) {
        this.log(LogLevel.WARN, 'WARN', message, context);
    }
    error(message, context) {
        this.log(LogLevel.ERROR, 'ERROR', message, context);
    }
    setLogLevel(level) {
        this.logLevel = level;
    }
}
exports.Logger = Logger;
exports.logger = Logger.getInstance();
