import * as moment from 'moment'
import * as config from './config'


enum Level {
    All,
    NoDebug,
    NoDebugNoInfo,
    NoDebugNoInfoNoWarning
}

var level = Level.NoDebug

function timestamp(): string {
    return moment().format('HH:mm:ss.SSS')
}

export function setLevel(value: string): void {
    switch (value) {
        case 'info':  level = Level.NoDebug; break
        case 'warn':  level = Level.NoDebugNoInfo; break
        case 'error': level = Level.NoDebugNoInfoNoWarning; break
        default:      level = Level.All
    }
}


export function info(message: string): void {
    if (level < Level.NoDebugNoInfo) {
        console.log(`${timestamp()} [ II ] ${message}`)
    }
}

export function warn(message: string): void {
    if (level < Level.NoDebugNoInfoNoWarning) {
        console.log(`${timestamp()} [ WW ] ${message}`)
    }
}

export function error(message: string): void {
    console.log(`${timestamp()} [ EE ] ${message}`)
}

export function success(message: string): void {
    console.log(`${timestamp()} [ OK ] ${message}`)
}

export function debug(message: string): void {
    if (level < Level.NoDebug) {
        console.log(`${timestamp()} [ DB ] ${message}`)
    }
}
