-- debuglevels.lua
WDIGI.Utils = WDIGI.Utils or {}

------------------------------------------------------------
-- DEBUG LEVELS
------------------------------------------------------------
WDIGI.DebugLevels = {
    ERROR = 1,
    WARN  = 2,
    INFO  = 3,
    DEBUG = 4,
    TRACE = 5,
}

WDIGI.Constants.LEVEL_ORDER = {
    ["TRACE"] = 5,
    ["DEBUG"] = 4,
    ["INFO"]  = 3,
    ["WARN"]  = 2,
    ["ERROR"] = 1,
}

-- Default level (quiet but useful)
WDIGI.CurrentDebugLevel = WDIGI.DebugLevels.ERROR

-- Ensure log buffer exists
WDIGI.DebugLog = WDIGI.DebugLog or {}

------------------------------------------------------------
-- LEVEL-SPECIFIC HELPERS
-- These call the Log() router defined in utilities.lua
------------------------------------------------------------
function WDIGI.Utils.Error(msg)
    WDIGI.Utils.Log(WDIGI.DebugLevels.ERROR, "[ERROR] " .. tostring(msg))
end

function WDIGI.Utils.Warn(msg)
    WDIGI.Utils.Log(WDIGI.DebugLevels.WARN, "[WARN] " .. tostring(msg))
end

function WDIGI.Utils.Info(msg)
    WDIGI.Utils.Log(WDIGI.DebugLevels.INFO, "[INFO] " .. tostring(msg))
end

function WDIGI.Utils.Debug(msg)
    WDIGI.Utils.Log(WDIGI.DebugLevels.DEBUG, "[DEBUG] " .. tostring(msg))
end

function WDIGI.Utils.Trace(msg)
    WDIGI.Utils.Log(WDIGI.DebugLevels.TRACE, "[TRACE] " .. tostring(msg))
end

------------------------------------------------------------
-- SLASH COMMAND: /wdigidebug <level>
------------------------------------------------------------
SLASH_WDIGIDEBUG1 = "/wdigidebug"
SlashCmdList["WDIGIDEBUG"] = function(msg)
    msg = msg:lower() or ""

    if msg == "off" then
        WDIGI.CurrentDebugLevel = WDIGI.DebugLevels.ERROR
        WDIGI.Utils.Info("Debug disabled (ERROR only)")

    elseif msg == "info" then
        WDIGI.CurrentDebugLevel = WDIGI.DebugLevels.INFO
        WDIGI.Utils.Info("Debug level set to INFO")

    elseif msg == "debug" then
        WDIGI.CurrentDebugLevel = WDIGI.DebugLevels.DEBUG
        WDIGI.Utils.Info("Debug level set to DEBUG")

    elseif msg == "trace" then
        WDIGI.CurrentDebugLevel = WDIGI.DebugLevels.TRACE
        WDIGI.Utils.Info("Debug level set to TRACE")

    elseif msg == "show" then
        WDIGI.Utils.ShowDebugConsole()

    elseif msg == "hide" then
        WDIGI.Utils.HideDebugConsole()

    else
        print("|cff00ffffWDIGI Debug Usage:|r")
        print("  /wdigidebug off")
        print("  /wdigidebug info")
        print("  /wdigidebug debug")
        print("  /wdigidebug trace")
        print("  /wdigidebug show")
        print("  /wdigidebug hide")
    end
end
