const { logger } = require('../../config/logger');

const normalizeContext = (context = {}) => ({
  tenant_id: context.tenant_id ?? context.tenantId ?? null,
  session_id: context.session_id ?? context.sessionId ?? null,
  message_id: context.message_id ?? context.messageId ?? null,
  module: context.module ?? null,
  event: context.event ?? null,
  step: context.step ?? null,
  duration: context.duration ?? null,
  error: context.error ?? null
});

const logInfo = (message, context) => {
  logger.info(message, normalizeContext(context));
};

const logWarn = (message, context) => {
  logger.warn(message, normalizeContext(context));
};

const logError = (message, context) => {
  logger.error(message, normalizeContext(context));
};

module.exports = {
  normalizeContext,
  logInfo,
  logWarn,
  logError
};
