interface LogInput {
  type: TypeOfMessage;
  message: string;
  data?: any;
  dataPrefix: string;
}

enum TypeOfMessage {
  Info = 'INFO',
  Error = 'ERROR',
  Debug = 'DEBUG'
}

const log = (...params) => { console.log(...params) }
const prefixTo = (prefix: string, message: string) => `[${prefix}]${message.startsWith('[') ? '' : ': '}`

export const logInfo = logInput => {
  const messagePrefix = prefixTo(TypeOfMessage.Info, logInput.message)
  log(`${messagePrefix}${logInput.message}`)
}

export const logError = logInput => {
  const messagePrefix = prefixTo(TypeOfMessage.Error, logInput.message)
  log(`${messagePrefix}${logInput.message}`)
  logInput.error && log('\n[Reason]:', logInput.error, '\n')
}

export const logDebug = logInput => {
  const isDebugOn = process.env.DEBUG || false
  if (!isDebugOn) return
  const messagePrefix = prefixTo(TypeOfMessage.Debug, logInput.message)
  log(`${messagePrefix}${logInput.message}`)
  logInput.data && log('\n[Debug data]:', logInput.data, '\n')
}
