-- A fully qualified outfit is one that has both arms, both legs, and a torso.

local function isFullyQualifiedOutfit(assets)
	for _, assetTypeId in pairs(bodyPartAssetTypeIds) do
		if not assets[assetTypeId] then
			return false
		end
	end

	return true
end

return function(outfit)
	return function(store)
		local fullReset = outfit.isEditable or isFullyQualifiedOutfit(outfit.assets)

		-- Do a full reset on a user costume, or a preset fully qualified one. Otherwise swap the existing parts.
		store:dispatch(EquipOutfit(outfit.assets, fullReset))

		if true then
			local selectedItem = store:getState().AvatarExperience.AvatarScene.TryOn.SelectedItem.itemId
			if selectedItem then
				store:dispatch(ClearSelectedItem())
				store:dispatch(CloseAllItemDetails(store:getState().Navigation.history))
			end
		end

		if fullReset then
			-- Preset costumes should not replace body colors.
			if not FFlagAvatarEditorKeepYourColor or
				(FFlagAvatarEditorKeepYourColor and not AvatarEditorUtils.isPresetCostume(outfit)) then
				store:dispatch(SetBodyColors(outfit.bodyColors))
			end
			store:dispatch(SetAvatarScales(outfit.scales))
			store:dispatch(SetAvatarType(outfit.avatarType))
		end
	end
end
