local function S()while IsLiveCheckActive==true do Madwork.HeartbeatWait()end end local function z(S)while S._is_pending==true do Madwork.HeartbeatWait()end end local function m(S,z,m)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\""..(z..("\"\059\075\101\121\058\""..(m..("\"\041 - \""..(tostring(S).."\""))))))table.insert(IssueQueue,os.clock())ProfileService.IssueSignal:Fire(tostring(S),z,m)end local function r(S,z)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 \""..(S..("\"\044 \075\101\121 \061 \""..(z.."\""))))ProfileService.CorruptionSignal:Fire(S,z)end local function Y(S,z,m,r)local Y=S[z]if Y==nil then Y={}S[z]=Y end local O=r(Y[m])if O==nil then return nil else Y[m]=DeepCopyTable(O)return DeepCopyTable(Y[m])end end local function O(S)return S[1]==PlaceId and S[2]==JobId end
----- Private functions -----

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
