function GlobalUpdates.AddActiveUpdate(k,N)if type(N)~="\116\097\098\108\101"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \073\110\118\097\108\105\100 \117\112\100\097\116\101\095\100\097\116\097")end if k._new_active_update_listeners~=nil then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \097\100\100 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \108\111\097\100\101\100 \080\114\111\102\105\108\101\059 \085\115\101 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")elseif k._update_handler_mode~=true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \097\100\100 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \118\105\101\119 \109\111\100\101\059 \085\115\101 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")end local z=k._updates_latest local L=z[1]+1 z[1]=L table.insert(z[2],{L,1;false;N})end function GlobalUpdates.ChangeActiveUpdate(z,N,k)if type(N)~="\110\117\109\098\101\114"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \073\110\118\097\108\105\100 \117\112\100\097\116\101\095\105\100")end if type(k)~="\116\097\098\108\101"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \073\110\118\097\108\105\100 \117\112\100\097\116\101\095\100\097\116\097")end if z._new_active_update_listeners~=nil then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\104\097\110\103\101 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \108\111\097\100\101\100 \080\114\111\102\105\108\101\059 \085\115\101 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")elseif z._update_handler_mode~=true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\104\097\110\103\101 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \118\105\101\119 \109\111\100\101\059 \085\115\101 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")end local L=z._updates_latest local l=nil for k,z in ipairs(L[2])do if N==z[1]then l=z break end end if l~=nil then if l[3]==true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\104\097\110\103\101 \108\111\099\107\101\100 \103\108\111\098\097\108 \117\112\100\097\116\101")end l[2]=l[2]+1 l[4]=k else error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \080\097\115\115\101\100 \110\111\110-\101\120\105\115\116\097\110\116 \117\112\100\097\116\101\095\105\100")end end function GlobalUpdates.ClearActiveUpdate(k,N)if type(N)~="\110\117\109\098\101\114"then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \073\110\118\097\108\105\100 \117\112\100\097\116\101\095\105\100 \097\114\103\117\109\101\110\116")end if k._new_active_update_listeners~=nil then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\108\101\097\114 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \108\111\097\100\101\100 \080\114\111\102\105\108\101\059 \085\115\101 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")elseif k._update_handler_mode~=true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\108\101\097\114 \097\099\116\105\118\101 \103\108\111\098\097\108 \117\112\100\097\116\101\115 \105\110 \118\105\101\119 \109\111\100\101\059 \085\115\101 \080\114\111\102\105\108\101\083\116\111\114\101\058\071\108\111\098\097\108\085\112\100\097\116\101\080\114\111\102\105\108\101\065\115\121\110\099\040\041")end local z=k._updates_latest local L=nil local l=nil for k,z in ipairs(z[2])do if N==z[1]then L=k l=z break end end if l~=nil then if l[3]==true then error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \067\097\110\'\116 \099\108\101\097\114 \108\111\099\107\101\100 \103\108\111\098\097\108 \117\112\100\097\116\101")end table.remove(z[2],L)else error("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \080\097\115\115\101\100 \110\111\110-\101\120\105\115\116\097\110\116 \117\112\100\097\116\101\095\105\100")end end

function GlobalUpdates:AddActiveUpdate(update_data)
	if type(update_data) ~= "table" then
		error("[ProfileService]: Invalid update_data")
	end
	if self._new_active_update_listeners ~= nil then
		error("[ProfileService]: Can't add active global updates in loaded Profile; Use ProfileStore:GlobalUpdateProfileAsync()")
	elseif self._update_handler_mode ~= true then
		error("[ProfileService]: Can't add active global updates in view mode; Use ProfileStore:GlobalUpdateProfileAsync()")
	end
	-- self._updates_latest = {}, -- [table] {update_index, {{update_id, version_id, update_locked, update_data}, ...}}
	local updates_latest = self._updates_latest
	local update_index = updates_latest[1] + 1 -- Incrementing global update index
	updates_latest[1] = update_index
	-- Add new active global update:
	table.insert(updates_latest[2], {update_index, 1, false, update_data})
end

function GlobalUpdates:ChangeActiveUpdate(update_id, update_data)
	if type(update_id) ~= "number" then
		error("[ProfileService]: Invalid update_id")
	end
	if type(update_data) ~= "table" then
		error("[ProfileService]: Invalid update_data")
	end
	if self._new_active_update_listeners ~= nil then
		error("[ProfileService]: Can't change active global updates in loaded Profile; Use ProfileStore:GlobalUpdateProfileAsync()")
	elseif self._update_handler_mode ~= true then
		error("[ProfileService]: Can't change active global updates in view mode; Use ProfileStore:GlobalUpdateProfileAsync()")
	end
	-- self._updates_latest = {}, -- [table] {update_index, {{update_id, version_id, update_locked, update_data}, ...}}
	local updates_latest = self._updates_latest
	local get_global_update = nil
	for _, global_update in ipairs(updates_latest[2]) do
		if update_id == global_update[1] then
			get_global_update = global_update
			break
		end
	end
	if get_global_update ~= nil then
		if get_global_update[3] == true then
			error("[ProfileService]: Can't change locked global update")
		end
		get_global_update[2] = get_global_update[2] + 1 -- Increment version id
		get_global_update[4] = update_data -- Set new global update data
	else
		error("[ProfileService]: Passed non-existant update_id")
	end
end

function GlobalUpdates:ClearActiveUpdate(update_id)
	if type(update_id) ~= "number" then
		error("[ProfileService]: Invalid update_id argument")
	end
	if self._new_active_update_listeners ~= nil then
		error("[ProfileService]: Can't clear active global updates in loaded Profile; Use ProfileStore:GlobalUpdateProfileAsync()")
	elseif self._update_handler_mode ~= true then
		error("[ProfileService]: Can't clear active global updates in view mode; Use ProfileStore:GlobalUpdateProfileAsync()")
	end
	-- self._updates_latest = {}, -- [table] {update_index, {{update_id, version_id, update_locked, update_data}, ...}}
	local updates_latest = self._updates_latest
	local get_global_update_index = nil
	local get_global_update = nil
	for index, global_update in ipairs(updates_latest[2]) do
		if update_id == global_update[1] then
			get_global_update_index = index
			get_global_update = global_update
			break
		end
	end
	if get_global_update ~= nil then
		if get_global_update[3] == true then
			error("[ProfileService]: Can't clear locked global update")
		end
		table.remove(updates_latest[2], get_global_update_index) -- Remove active global update
	else
		error("[ProfileService]: Passed non-existant update_id")
	end
end
