UytDistanceMultiplierEvent = {}
local UytDistanceMultiplierEvent_mt = Class(UytDistanceMultiplierEvent, Event)
InitEventClass(UytDistanceMultiplierEvent, "UytDistanceMultiplierEvent")

function UytDistanceMultiplierEvent.emptyNew()
	return Event.new(UytDistanceMultiplierEvent_mt)
end

function UytDistanceMultiplierEvent.new(tyresDistanceMultiplier)
	local self = UytDistanceMultiplierEvent.emptyNew()
	self.tyreDistanceMultiplier = tyresDistanceMultiplier
	return self
end

function UytDistanceMultiplierEvent.readStream(self, streamId, connection)
	self.tyreDistanceMultiplier = streamReadFloat32(streamId)

    self:run(connection)
end

function UytDistanceMultiplierEvent.writeStream(self, streamId, connection)
	streamWriteFloat32(streamId, self.tyreDistanceMultiplier)
end

function UytDistanceMultiplierEvent.run(self, connection)
	if self.tyreDistanceMultiplier ~= nil then
		if g_server ~= nil
			and AAIntegration ~= nil
			and AAIntegration.isAuthorizedSettingsConnection ~= nil
			and not AAIntegration.isAuthorizedSettingsConnection(connection) then
			connection:sendEvent(UytDistanceMultiplierEvent.new(UseYourTyres.tyreDistanceMultiplier))
			return
		end

		UseYourTyres.tyreDistanceMultiplier = math.clamp(tonumber(self.tyreDistanceMultiplier) or 1, 0.00001, 100)
		UseYourTyresSettings:updateSettings()      		

		if not connection:getIsServer() then
			g_server:broadcastEvent(UytDistanceMultiplierEvent.new(UseYourTyres.tyreDistanceMultiplier), false, connection)
		else
			
		end
		-- print("Applied multiplier to the useYourTyres object: " .. UseYourTyres.tyreDistanceMultiplier)
	end
end
