function prepareMigrationData(aVariants, aFlVariantsFinalState, aChanges, mPropertyBag, VariantManager) {
		var oMigrationData = {
			contextBasedAdaptations: [],
			flexObjects: []
		};

		// Calculate final states for all variants by merging all changes and cache it
		var oFinalStates = {};
		aVariants.forEach(function(oVariant) {
			oFinalStates[oVariant.getId()] = getFinalState(aFlVariantsFinalState, aChanges, oVariant);
		});

		// Group variants by their corresponding unique context for all layers {key: context, value: variants}
		var oGrouped = groupVariantsByContextEntry(aVariants, oFinalStates);
		var mUniqueContexts = oGrouped.uniqueContexts;
		var aUnrestrictedViews = oGrouped.unrestrictedViews;

		// Iterate over each unique context to copy context related variants and changes (for both: customer layer only), as well as to create context based adaptation
		Object.entries(mUniqueContexts).forEach(function(aEntry) {
			var sContext = aEntry[0];
			var oUniqueContext = aEntry[1];
			// add unrestricted variants
			oUniqueContext.variants = oUniqueContext.variants.concat(aUnrestrictedViews);

			// Prepare adaptation
			var sContextBasedAdaptationId = oUniqueContext.contextBasedAdaptationId;
			var oContextBasedAdaptation = {
				id: sContextBasedAdaptationId,
				title: _oResourceBundle.getText("CBA_MIGRATED_ADAPTATION_TITLE", [sContext]),
				contexts: {
					role: [sContext]
				},
				priority: 0
			};
			oMigrationData.contextBasedAdaptations.push(oContextBasedAdaptation);

			// Filter variants for customer layer. Only customer layer variants must be copied
			var aCustomerLayerVariants = oUniqueContext.variants.filter(function(oVariant) {
				return oVariant.getLayer() === Layer.CUSTOMER;
			});
			var mFileNames = new Map();
			var aCopiedVariants = copyVariants(aCustomerLayerVariants, mFileNames, sContextBasedAdaptationId);
			// Add copied variants to migration data
			aCopiedVariants.forEach(function(oContextRelevantVariant) {
				oMigrationData.flexObjects.push(oContextRelevantVariant.convertToFileContent());
			});

			// Find variant relevant changes
			var aUniqueContextVariantIds = oUniqueContext.variants.map(function(oVariant) {
				return oVariant.getId();
			});
			var aVariantIdsNotInUniqueContext = aVariants.map(function(oVariant) {
				return oVariant.getId();
			}).filter(function(sVariantId) {
				return aUniqueContextVariantIds.indexOf(sVariantId) < 0;
			});
			var aChangesToCopy = filterChangesForAdaptation(aVariantIdsNotInUniqueContext, aChanges);
			var aCopiedChanges = copyChanges(aChangesToCopy, mFileNames, sContextBasedAdaptationId);
			aCopiedChanges.forEach(function(oCopiedChange) {
				oMigrationData.flexObjects.push(oCopiedChange.convertToFileContent());
			});

			// Hide variants from lower layers if not in scope
			aVariants.forEach(function(oVariant) {
				if (oVariant.getLayer() !== Layer.CUSTOMER && aUniqueContextVariantIds.indexOf(oVariant.getId()) < 0) {
					oMigrationData.flexObjects.push(
						createChangeSetVisibleFalseToRestrictedVariant(oVariant, mPropertyBag, sContextBasedAdaptationId, VariantManager)
					);
				}
			});
		});

		// Hide all variants restricted in default adaptation if not already hidden
		aVariants.forEach(function(oVariant) {
			var oFinalState = oFinalStates[oVariant.getId()];
			var bRestricted = aUnrestrictedViews.indexOf(oVariant) < 0;
			if (oFinalState.visible === true && bRestricted) {
				oMigrationData.flexObjects.push(
					createChangeSetVisibleFalseToRestrictedVariant(oVariant, mPropertyBag, undefined, VariantManager)
				);
			}
		});

		return oMigrationData;
	}
Prepares data for migration of variants. Context-based adaptations don't support context-dependent
variants. Therefore, a migration must be done. During the migration process, variants and changes are copied for each unique context,
and added to a context-based adaptation. These context-based adaptations have one context.
@param {sap.ui.fl.apply._internal.flexObjects.Variant[]} aVariants - Variants from all layers that are relevant to be copied
@param {object[]} aFlVariantsFinalState - FL Variants from VariantManagementState holding final state
@param {sap.ui.fl.apply._internal.flexObjects.FlexObject[]} aChanges - Changes from customer layer that need to be copied
@param {object} mPropertyBag - Object with parameters as properties
@param {string} mPropertyBag.appId - App reference
@param {string} mPropertyBag.layer - Working layer
@param {sap.ui.core.Control} mPropertyBag.control - Control for which the request is done
@returns {object} Returns a object containing context-based adaptations and changes/variants as FlexObjects that must be migrated