-- Public Functions

function UpgradeManager:AddUpgrade(player)
	local stats = player:WaitForChild("stats")
	local points = stats:WaitForChild(GameSettings.pointsName)
	local upgrades = stats:WaitForChild(GameSettings.upgradeName)
	upgrades.Value = upgrades.Value + 1
	self:SetWalkspeedToCurrentUpgrade(player)
	ParticleController:CreateUpgradeParticle(player)
	
	DataStore:SetPoints(player, points.Value)
	DataStore:SetUpgrades(player, upgrades.Value)
end

function UpgradeManager:BuyUpgrade(player)
	local stats = player:WaitForChild("stats")
	local points = stats:WaitForChild(GameSettings.pointsName)
	local upgrades = stats:WaitForChild(GameSettings.upgradeName)
	
	local cost = GameSettings.upgradeCost(upgrades.Value)
	
	-- Check if the player can make the purchase and if so, allow them
	if points.Value >= cost then
		points.Value = points.Value - cost
		upgrades.Value = upgrades.Value + 1
		self:SetWalkspeedToCurrentUpgrade(player)
		
		DataStore:SetPoints(player, points.Value)
		DataStore:SetUpgrades(player, upgrades.Value)
		ParticleController:CreateUpgradeParticle(player)
	else
		-- Not enough points
	end
end

return UpgradeManager
