/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

use std::fmt::Display;

use jellyobject::fields;
use serde::{Deserialize, Serialize};

fields! {
    IM_PATH: &str = b"Ipth";
    IM_MTIME: u64 = b"Imtm";
}

#[derive(Serialize, Deserialize, Clone)]
pub struct LogLine {
    pub time: String,
    pub module: Option<&'static str>,
    pub level: LogLevel,
    pub message: String,
}

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq)]
pub enum LogLevel {
    Trace,
    Debug,
    Info,
    Warn,
    Error,
}
impl Display for LogLevel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(match self {
            LogLevel::Trace => "trace",
            LogLevel::Debug => "debug",
            LogLevel::Info => "info",
            LogLevel::Warn => "warn",
            LogLevel::Error => "error",
        })
    }
}