{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}

module Biz.Log
  ( Lvl (..),
    good,
    pass,
    info,
    warn,
    fail,
    -- | Low-level
    msg,
    br,
  )
where

import Alpha hiding (pass)
import qualified Data.Text as Text
import Rainbow (chunk, fore, green, putChunk, red, white, yellow)

data Lvl = Good | Pass | Info | Warn | Fail

msg :: Lvl -> [Text] -> IO ()
msg lvl labels = putChunk <| fore color <| clear <> txt <> "\r"
  where
    txt = chunk <| Text.intercalate gap (label : labels)
    (color, label) = case lvl of
      Good -> (green, "good")
      Pass -> (green, "pass")
      Info -> (white, "info")
      Warn -> (yellow, "warn")
      Fail -> (red, "fail")
    gap = ":  "
    clear = "\ESC[2K"

br :: IO ()
br = putChunk "\n"

good, pass, info, warn, fail :: [Text] -> IO ()
good = msg Good
pass = msg Pass
info = msg Info
warn = msg Warn
fail = msg Fail