// Copyright (C) 2022-2023 Enrico Guiraud
//
// This file is part of Kobold, a static site generator with a friendly CLI.
//
// Kobold is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Kobold is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kobold. If not, see <http://www.gnu.org/licenses/>.

use colorful::Color;
use colorful::Colorful;

pub enum Lvl {
    Error,
    Info,
    Warning,
}

impl Lvl {
    pub fn as_color(&self) -> Color {
        match self {
            Lvl::Error => Color::Red,
            Lvl::Info => Color::LightGray,
            Lvl::Warning => Color::Yellow,
        }
    }
}

pub fn log(lvl: Lvl, msg: &str) {
    let head = match lvl {
        Lvl::Error => "[ERROR]".bold().color(lvl.as_color()),
        Lvl::Info => "[INFO]".bold().color(lvl.as_color()),
        Lvl::Warning => "[WARNING]".bold().color(lvl.as_color()),
    };

    eprintln!("{} {}", &head, &msg);
}
