--- @author DoomTero 2026

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
