-- logger.lua
local _, ns = ...
local Logger = {}
ns.Logger = Logger

local levels = { debug = 1, info = 2, warn = 3, error = 4 }

local function canLog(level)
  local target = levels[MagicTranslatorDB.logLevel or "info"]
  return levels[level] >= target
end

local function fmtKV(tbl)
  local parts = {}
  for k, v in pairs(tbl or {}) do table.insert(parts, tostring(k) .. "=" .. tostring(v)) end
  return table.concat(parts, " ")
end

function Logger:Debug(msg, kv)
  if canLog("debug") then DEFAULT_CHAT_FRAME:AddMessage("|cff8888ff[OT][DEBUG]|r " .. msg .. " " .. fmtKV(kv)) end
end

function Logger:Info(msg, kv)
  if canLog("info") then DEFAULT_CHAT_FRAME:AddMessage("|cff88ff88[OT]|r " .. msg .. " " .. fmtKV(kv)) end
end

function Logger:Warn(msg, kv)
  if canLog("warn") then DEFAULT_CHAT_FRAME:AddMessage("|cffffcc00[OT][WARN]|r " .. msg .. " " .. fmtKV(kv)) end
end

function Logger:Error(msg, kv)
  DEFAULT_CHAT_FRAME:AddMessage("|cffff5555[OT][ERROR]|r " .. msg .. " " .. fmtKV(kv))
end
