class Logger {
    constructor(context) {
        this.context = context;
    }

    formatMessage(level, message, data = null) {
        const timestamp = new Date().toISOString();
        const context = this.context ? `[${this.context}]` : '';
        if (data) {
            return `[${timestamp}] ${level}${context}: ${message} ${JSON.stringify(data, null, 2)}`;
        }
        return `[${timestamp}] ${level}${context}: ${message}`;
    }

    debug(message, data = null) {
        console.log(this.formatMessage('DEBUG', message, data));
    }

    info(message, data = null) {
        console.log(this.formatMessage('INFO', message, data));
    }

    warn(message, data = null) {
        console.warn(this.formatMessage('WARN', message, data));
    }

    error(message, error = null) {
        console.error(this.formatMessage('ERROR', message, {
            message: error?.message,
            stack: error?.stack,
            ...error
        }));
    }
}

module.exports = Logger;