local ns = _G.WoWTranslate_UK_NS

local factory = {}
ns.EventHandlerFactory = factory

function factory.Create()
    local handler = {}
    handler._callbacks = {}
    handler._frame = CreateFrame("Frame")

    function handler:Register(callback, ...)
        local events = { ... }
        for _, event in ipairs(events) do
            self._callbacks[event] = self._callbacks[event] or {}
            if #self._callbacks[event] == 0 then
                self._frame:RegisterEvent(event)
            end
            table.insert(self._callbacks[event], callback)
        end
    end

    handler._frame:SetScript("OnEvent", function(_, event, ...)
        local callbacks = handler._callbacks[event]
        if not callbacks then
            return
        end
        for i = 1, #callbacks do
            callbacks[i](event, ...)
        end
    end)

    return handler
end