function GlobalUpdates.AddActiveUpdate(t,k)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 t._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 t._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 i=t._updates_latest local r=i[1]+1 i[1]=r table.insert(i[2],{r,1;false,k})end function GlobalUpdates.ChangeActiveUpdate(i,k,t)if type(k)~="\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(t)~="\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 i._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 i._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 r=i._updates_latest local y=nil for t,i in ipairs(r[2])do if k==i[1]then y=i break end end if y~=nil then if y[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 y[2]=y[2]+1 y[4]=t 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(t,k)if type(k)~="\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 t._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 t._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 i=t._updates_latest local r=nil local y=nil for t,i in ipairs(i[2])do if k==i[1]then r=t y=i break end end if y~=nil then if y[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(i[2],r)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
-- EXPOSED TO "update_handler" DURING ProfileStore:GlobalUpdateProfileAsync() CALL
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
