package io

object Logger {
    enum class Level {
        DEBUG, INFO, WARN, ERROR
    }

    val defaultLevel: Level = Level.WARN
    var level: Level = defaultLevel

    private val io = Terminal()

    fun log(message: String, messageLevel: Level = defaultLevel, onlyIf: Boolean) {
        if (level <= messageLevel && onlyIf) {
            io.checkNewLine()
            val text = "$messageLevel: $message\n"
            io.say(text)
        }
    }

    fun debug(message: String, onlyIf: Boolean = true) = log(message, Level.DEBUG, onlyIf)
    fun info(message: String, onlyIf: Boolean = true) = log(message, Level.INFO, onlyIf)
    fun warn(message: String, onlyIf: Boolean = true) = log(message, Level.WARN, onlyIf)
    fun error(message: String, onlyIf: Boolean = true) = log(message, Level.ERROR, onlyIf)
}
