local function G()while IsLiveCheckActive==true do Madwork.HeartbeatWait()end end local function a(G)while G._is_pending==true do Madwork.HeartbeatWait()end end local function t(G,a,t)warn("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \068\097\116\097\083\116\111\114\101 \065\080\073 \101\114\114\111\114 \040\083\116\111\114\101\058\""..(a..("\"\059\075\101\121\058\""..(t..("\"\041 - \""..(tostring(G).."\""))))))table.insert(IssueQueue,os.clock())ProfileService.IssueSignal:Fire(tostring(G),a,t)end local function d(G,a)warn("\091\080\114\111\102\105\108\101\083\101\114\118\105\099\101\093\058 \080\114\111\102\105\108\101 \099\111\114\114\117\112\116\105\111\110 - \080\114\111\102\105\108\101\083\116\111\114\101 \061 \""..(G..("\"\044 \075\101\121 \061 \""..(a.."\""))))ProfileService.CorruptionSignal:Fire(G,a)end local function T(G,a,t,d)local T=G[a]if T==nil then T={}G[a]=T end local p=d(T[t])if p==nil then return nil else T[t]=DeepCopyTable(p)return DeepCopyTable(T[t])end end local function p(G)return G[1]==PlaceId and G[2]==JobId end


local function WaitForLiveAccessCheck() -- This function was created to prevent the ProfileService module yielding execution when required
	while IsLiveCheckActive == true do
		Madwork.HeartbeatWait()
	end
end

local function WaitForPendingProfileStore(profile_store)
	while profile_store._is_pending == true do
		Madwork.HeartbeatWait()
	end
end

local function RegisterIssue(error_message, profile_store_name, profile_key) -- Called when a DataStore API call errors
	warn("[ProfileService]: DataStore API error (Store:\"" .. profile_store_name .. "\";Key:\"" .. profile_key .. "\") - \"" .. tostring(error_message) .. "\"")
	table.insert(IssueQueue, os.clock()) -- Adding issue time to queue
	ProfileService.IssueSignal:Fire(tostring(error_message), profile_store_name, profile_key)
end

local function RegisterCorruption(profile_store_name, profile_key) -- Called when a corrupted profile is loaded
	warn("[ProfileService]: Profile corruption - ProfileStore = \"" .. profile_store_name .. "\", Key = \"" .. profile_key .. "\"")
	ProfileService.CorruptionSignal:Fire(profile_store_name, profile_key)
end

local function MockUpdateAsync(mock_data_store, profile_store_name, key, transform_function)
	local profile_store = mock_data_store[profile_store_name]
	if profile_store == nil then
		profile_store = {}
		mock_data_store[profile_store_name] = profile_store
	end
	local transform = transform_function(profile_store[key])
	if transform == nil then
		return nil
	else
		profile_store[key] = DeepCopyTable(transform)
		return DeepCopyTable(profile_store[key])
	end
end

local function IsThisSession(session_tag)
	return session_tag[1] == PlaceId and session_tag[2] == JobId
end
