--- @author DoomTero 2026
-- @copyright 2026 DoomTero - ZomboRut original work. ref:fdb88369
-- @license Proprietary. Not licensed for reuse, redistribution or derivative works without written permission from DoomTero. Ask - permission is obtainable. See ZomboRut/LICENSE.txt

local Callbacks = {}

local handlers = {}
local missing  = {}

local function dispatch(module, command, args)
	if not isClient() then return end
	if module ~= ZomboRutConfig.CommandName then return end
	if missing[command] then return end

	local fn = handlers[command]
	if fn == nil then
		local ok, mod = pcall(require, "ZomboRut/ClientCommands/" .. command)
		if ok and type(mod) == "function" then
			fn = mod
			handlers[command] = mod
		else
			missing[command] = true
			return
		end
	end
	fn(args)
end

function Callbacks:sendClientCommand(command, ...)
	if not isClient() then return end
	sendClientCommand(getPlayer(), ZomboRutConfig.CommandName, command, {...})
end

Events.OnServerCommand.Add(dispatch)

return Callbacks
