package com.jihe.punchnet.sdlan.logs

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

const val ColorPrefix = "\u001b"
const val GreenColor = "${ColorPrefix}[0;32m"
const val BlueColor = "${ColorPrefix}[0;34m"
const val YellowColor = "${ColorPrefix}[0;33m"
const val RedColor = "${ColorPrefix}[0;31m"
const val ColorReset = "${ColorPrefix}[0;0m"

interface Logger {
    val format: DateTimeFormatter
    fun debugf(formatter: ()->String) {
        val now = LocalDateTime.now().format(format)
        println("${GreenColor}DEBU:${ColorReset}[$now] ${formatter()}")
    }
    fun infof(formatter: ()->String) {
        val now = LocalDateTime.now().format(format)
        println("${BlueColor}INFO:${ColorReset}[$now] ${formatter()}")
    }
    fun warning(formatter: ()->String) {
        val now = LocalDateTime.now().format(format)
        println("${YellowColor}WARN:${ColorReset}[$now] ${formatter()}")
    }
    fun errorf(formatter: ()->String) {
        val now = LocalDateTime.now().format(format)
        println("${RedColor}ERRO:${ColorReset}[$now] ${formatter()}")
    }
    fun criticalf(formatter: ()->String) {
        val now = LocalDateTime.now().format(format)
        println("${RedColor}CRIT:${ColorReset}[$now] ${formatter()}")
    }
}

object TerminalLogger: Logger {
    override val format: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm::s")
}