using MsLogLevel = Microsoft.Extensions.Logging.LogLevel;

namespace ROLAC.API.Entities.Logging;

/// <summary>
/// Persisted severity for system and audit logs. Byte-backed so it stores compactly
/// as <c>smallint</c> and sorts/filters by ordinal. Deliberately omits the
/// <see cref="MsLogLevel.None"/> sentinel (value 6) — "None" means "log nothing" and
/// is meaningless once a row already exists.
/// </summary>
public enum LogLevelEnum : byte
{
    Trace       = 0,
    Debug       = 1,
    Information  = 2,
    Warning     = 3,
    Error       = 4,
    Critical    = 5,
}

public static class LogLevelMap
{
    /// <summary>
    /// Maps a framework <see cref="MsLogLevel"/> to our persisted enum.
    /// <see cref="MsLogLevel.None"/> falls through to <see cref="LogLevelEnum.Critical"/>
    /// (it never reaches the sink because the floor filter drops it first).
    /// </summary>
    public static LogLevelEnum FromMs(MsLogLevel level) => level switch
    {
        MsLogLevel.Trace       => LogLevelEnum.Trace,
        MsLogLevel.Debug       => LogLevelEnum.Debug,
        MsLogLevel.Information => LogLevelEnum.Information,
        MsLogLevel.Warning     => LogLevelEnum.Warning,
        MsLogLevel.Error       => LogLevelEnum.Error,
        MsLogLevel.Critical    => LogLevelEnum.Critical,
        _                      => LogLevelEnum.Critical,
    };
}
