--[[
for a,b in pairs(game.ServerScriptService.MainModule.Server.Morphs:GetDescendants()) do
	if b:IsA("Decal") and b.Name ~= "face" and b.Parent.Name == "Head" then
		print("CHANGED: ".. b.Name.." | "..b.Parent.Parent.Name)
		b.Name = "face"
	end
end
--]]


local bundleCache = {} -- cache HumanoidDescriptions retrieved from bundles to reduce API calls
function module:ApplyBundle(humanoid, bundleId)
	local HumanoidDescription = bundleCache[bundleId]
	if not HumanoidDescription then
		local success, bundleDetails = pcall(function() return main.assetService:GetBundleDetailsAsync(bundleId) end)
		if success and bundleDetails then
			for _, item in next, bundleDetails.Items do
				if item.Type == "UserOutfit" then
					success, HumanoidDescription = pcall(function() return main.players:GetHumanoidDescriptionFromOutfitId(item.Id) end)
					bundleCache[bundleId] = HumanoidDescription
					break
				end
			end
		end
	end
	if not HumanoidDescription then return end
	local newDescription = humanoid:GetAppliedDescription()
	local defaultDescription = Instance.new("HumanoidDescription")
	for _, property in next, {"BackAccessory", "BodyTypeScale", "ClimbAnimation", "DepthScale", "Face", "FaceAccessory", "FallAnimation", "FrontAccessory", "GraphicTShirt", "HairAccessory", "HatAccessory", "Head", "HeadColor", "HeadScale", "HeightScale", "IdleAnimation", "JumpAnimation", "LeftArm", "LeftArmColor", "LeftLeg", "LeftLegColor", "NeckAccessory", "Pants", "ProportionScale", "RightArm", "RightArmColor", "RightLeg", "RightLegColor", "RunAnimation", "Shirt", "ShouldersAccessory", "SwimAnimation", "Torso", "TorsoColor", "WaistAccessory", "WalkAnimation", "WidthScale"} do
		if HumanoidDescription[property] ~= defaultDescription[property] then -- property is not the default value
			newDescription[property] = HumanoidDescription[property]
		end
	end
	humanoid:ApplyDescription(newDescription)
end




return module
