private void populateManagedDiskInputDetails(
            A2ASwitchProtectionInput a2aSwitchInput,
            ReplicationProtectedItem replicationProtectedItemResponse)
        {
            if (this.AzureToAzureDiskReplicationConfiguration == null ||
                this.AzureToAzureDiskReplicationConfiguration.Length == 0)
            {
                var a2aReplicationDetails = ((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails);
                if (!a2aReplicationDetails.FabricObjectId.ToLower().Contains(ARMResourceTypeConstants.Compute.ToLower()))
                {
                    throw new Exception("Pass AzureToAzureDiskReplicationConfiguration for classic VMs");
                }
                var vmName = a2aReplicationDetails.RecoveryAzureVMName;
                var vmRg   = Utilities.GetValueFromArmId(
                    a2aReplicationDetails.RecoveryAzureResourceGroupId,
                    ARMResourceTypeConstants.ResourceGroups);
                var virtualMachine = this.ComputeManagementClient.GetComputeManagementClient.
                                     VirtualMachines.GetWithHttpMessagesAsync(vmRg, vmName).GetAwaiter().GetResult().Body;

                // Passing all managedDisk data if no details is passed.
                var osDisk = virtualMachine.StorageProfile.OsDisk;
                a2aSwitchInput.VmManagedDisks.Add(new A2AVmManagedDiskInputDetails
                {
                    DiskId = osDisk.ManagedDisk.Id,
                    RecoveryResourceGroupId             = this.RecoveryResourceGroupId,
                    PrimaryStagingAzureStorageAccountId = this.LogStorageAccountId,
                    RecoveryReplicaDiskAccountType      = osDisk.ManagedDisk.StorageAccountType.toStorageString(),
                    RecoveryTargetDiskAccountType       = osDisk.ManagedDisk.StorageAccountType.toStorageString()
                });
                if (virtualMachine.StorageProfile.DataDisks != null)
                {
                    foreach (var dataDisk in virtualMachine.StorageProfile.DataDisks)
                    {
                        a2aSwitchInput.VmManagedDisks.Add(new A2AVmManagedDiskInputDetails
                        {
                            DiskId = dataDisk.ManagedDisk.Id,
                            RecoveryResourceGroupId             = this.RecoveryResourceGroupId,
                            PrimaryStagingAzureStorageAccountId = this.LogStorageAccountId,
                            RecoveryReplicaDiskAccountType      = dataDisk.ManagedDisk.StorageAccountType.toStorageString(),
                            RecoveryTargetDiskAccountType       = dataDisk.ManagedDisk.StorageAccountType.toStorageString()
                        });
                    }
                }
            }
            else
            {
                foreach (ASRAzuretoAzureDiskReplicationConfig disk in this.AzureToAzureDiskReplicationConfiguration)
                {
                    a2aSwitchInput.VmManagedDisks.Add(new A2AVmManagedDiskInputDetails
                    {
                        DiskId = disk.DiskId,
                        RecoveryResourceGroupId             = disk.RecoveryResourceGroupId,
                        RecoveryReplicaDiskAccountType      = disk.RecoveryReplicaDiskAccountType,
                        RecoveryTargetDiskAccountType       = disk.RecoveryTargetDiskAccountType,
                        PrimaryStagingAzureStorageAccountId = this.LogStorageAccountId,
                    });
                }
            }
        }
        private void populateUnManagedDiskInputDetails(string fabricFriendlyName,
                                                       A2ASwitchProtectionInput a2aSwitchInput,
                                                       ReplicationProtectedItem replicationProtectedItemResponse)
        {
            if (this.AzureToAzureDiskReplicationConfiguration == null ||
                this.AzureToAzureDiskReplicationConfiguration.Length == 0)
            {
                if (fabricFriendlyName !=
                    this.ProtectionContainerMapping.TargetFabricFriendlyName &&
                    this.RecoveryAzureStorageAccountId == null)
                {
                    throw new ArgumentException(string.Format(Resources.InvalidRecoveryAzureStorageAccountIdDiskInput));
                }

                foreach (var disk in ((A2AReplicationDetails)replicationProtectedItemResponse
                                      .Properties.ProviderSpecificDetails)
                         .ProtectedDisks)
                {
                    a2aSwitchInput.VmDisks.Add(new A2AVmDiskInputDetails
                    {
                        DiskUri = disk.RecoveryDiskUri,
                        RecoveryAzureStorageAccountId =
                            fabricFriendlyName ==
                            this.ProtectionContainerMapping.TargetFabricFriendlyName &&
                            this.RecoveryAzureStorageAccountId == null ?
                            disk.PrimaryDiskAzureStorageAccountId :
                            this.RecoveryAzureStorageAccountId,
                        PrimaryStagingAzureStorageAccountId =
                            this.LogStorageAccountId,
                    });
                }
            }
            else
            {
                foreach (ASRAzuretoAzureDiskReplicationConfig disk in this.AzureToAzureDiskReplicationConfiguration)
                {
                    // logstorage account id in required param cann't be null.
                    if (string.IsNullOrEmpty(disk.RecoveryAzureStorageAccountId))
                    {
                        throw new PSArgumentException(
                                  string.Format(
                                      Properties.Resources.InvalidRecoveryAzureStorageAccountIdDiskInput,
                                      disk.VhdUri));
                    }

                    a2aSwitchInput.VmDisks.Add(new A2AVmDiskInputDetails
                    {
                        DiskUri = disk.VhdUri,
                        RecoveryAzureStorageAccountId       = disk.RecoveryAzureStorageAccountId,
                        PrimaryStagingAzureStorageAccountId =
                            disk.LogStorageAccountId
                    });
                }
            }
        }
        /// <summary>
        ///     Switches protection from one container to another or one replication provider to another.
        /// </summary>
        private void A2ARPIReprotect()
        {
            var switchProtectionInputProperties = new SwitchProtectionInputProperties()
            {
                ReplicationProtectedItemName = this.ReplicationProtectedItem.Name,
                ProviderSpecificDetails      = new SwitchProtectionProviderSpecificInput()
            };
            var fabricFriendlyName =
                this.ReplicationProtectedItem.PrimaryFabricFriendlyName;
            SwitchProtectionInput input = new SwitchProtectionInput()
            {
                Properties = switchProtectionInputProperties
            };

            if (0 == string.Compare(
                    this.ReplicationProtectedItem.ReplicationProvider,
                    Constants.A2A,
                    StringComparison.OrdinalIgnoreCase))
            {
                var a2aSwitchInput = new A2ASwitchProtectionInput()
                {
                    PolicyId            = this.ProtectionContainerMapping.PolicyId,
                    RecoveryContainerId =
                        this.ProtectionContainerMapping.TargetProtectionContainerId,
                    VmDisks                          = new List <A2AVmDiskInputDetails>(),
                    VmManagedDisks                   = new List <A2AVmManagedDiskInputDetails>(),
                    RecoveryResourceGroupId          = this.RecoveryResourceGroupId,
                    RecoveryCloudServiceId           = this.RecoveryCloudServiceId,
                    RecoveryAvailabilitySetId        = this.RecoveryAvailabilitySetId,
                    RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId,
                };

                // Fetch the latest Protected item objects
                var replicationProtectedItemResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(
                        this.fabricName,
                        this.protectionContainerName,
                        this.ReplicationProtectedItem.Name);

                if (fabricFriendlyName != this.ProtectionContainerMapping.TargetFabricFriendlyName)
                {
                    throw new ArgumentException(
                              string.Format(Resources.InvalidSwitchParamRPIAndProtectionContainerMapping,
                                            fabricFriendlyName,
                                            this.ProtectionContainerMapping.TargetFabricFriendlyName));
                }

                // unmanagedDisk case
                if (((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails).ProtectedDisks != null &&
                    ((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails).ProtectedDisks.Count > 0)
                {
                    populateUnManagedDiskInputDetails(fabricFriendlyName, a2aSwitchInput, replicationProtectedItemResponse);
                }
                else if (this.AzureToAzureDiskReplicationConfiguration == null &&
                         ((A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails).ProtectedManagedDisks != null)
                {
                    populateManagedDiskInputDetails(a2aSwitchInput, replicationProtectedItemResponse);
                }

                input.Properties.ProviderSpecificDetails = a2aSwitchInput;
            }

            var response =
                RecoveryServicesClient.StartSwitchProtection(
                    this.fabricName,
                    this.protectionContainerName,
                    input);

            var jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(
                    PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Switches protection from one container to another or one replication provider to another.
        /// </summary>
        private void A2ARPIReprotect()
        {
            var switchProtectionInputProperties = new SwitchProtectionInputProperties()
            {
                ReplicationProtectedItemName = this.ReplicationProtectedItem.Name,
                ProviderSpecificDetails      = new SwitchProtectionProviderSpecificInput()
            };
            var fabricFriendlyName =
                this.ReplicationProtectedItem.PrimaryFabricFriendlyName;
            SwitchProtectionInput input = new SwitchProtectionInput()
            {
                Properties = switchProtectionInputProperties
            };

            if (0 == string.Compare(
                    this.ReplicationProtectedItem.ReplicationProvider,
                    Constants.A2A,
                    StringComparison.OrdinalIgnoreCase))
            {
                var a2aSwitchInput = new A2ASwitchProtectionInput()
                {
                    PolicyId            = this.ProtectionContainerMapping.PolicyId,
                    RecoveryContainerId =
                        this.ProtectionContainerMapping.TargetProtectionContainerId,
                    VmDisks = new List <A2AVmDiskInputDetails>(),
                    RecoveryResourceGroupId   = this.RecoveryResourceGroupId,
                    RecoveryCloudServiceId    = this.RecoveryCloudServiceId,
                    RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId
                };

                // Fetch the latest Protected item objects
                var replicationProtectedItemResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(
                        this.fabricName,
                        this.protectionContainerName,
                        this.ReplicationProtectedItem.Name);

                if (fabricFriendlyName != this.ProtectionContainerMapping.TargetFabricFriendlyName)
                {
                    throw new ArgumentException(
                              string.Format(Resources.InvalidSwitchParamRPIAndProtectionContainerMapping,
                                            fabricFriendlyName,
                                            this.ProtectionContainerMapping.TargetFabricFriendlyName));
                }

                // At a time only Disk or managedDisk details will be present.
                // Will check with retieved protectedItem weather correct disk mapping is passed and then create the relevant object
                // and pass as input to service.
                if (this.AzureToAzureDiskReplicationConfiguration == null || this.AzureToAzureDiskReplicationConfiguration.Length == 0)
                {
                    if (fabricFriendlyName !=
                        this.ProtectionContainerMapping.TargetFabricFriendlyName &&
                        RecoveryAzureStorageAccountId == null)
                    {
                        throw new ArgumentException(Resources.InvalidRecoveryAzureStorageAccountId);
                    }

                    foreach (var disk in ((A2AReplicationDetails)replicationProtectedItemResponse
                                          .Properties.ProviderSpecificDetails)
                             .ProtectedDisks)
                    {
                        a2aSwitchInput.VmDisks.Add(new A2AVmDiskInputDetails
                        {
                            DiskUri = disk.RecoveryDiskUri,
                            RecoveryAzureStorageAccountId =
                                fabricFriendlyName ==
                                this.ProtectionContainerMapping.TargetFabricFriendlyName &&
                                this.RecoveryAzureStorageAccountId == null ?
                                disk.PrimaryDiskAzureStorageAccountId :
                                this.RecoveryAzureStorageAccountId,
                            PrimaryStagingAzureStorageAccountId =
                                this.LogStorageAccountId,
                        });
                    }
                }
                else
                {
                    foreach (ASRAzuretoAzureDiskReplicationConfig disk in this.AzureToAzureDiskReplicationConfiguration)
                    {
                        if (string.IsNullOrEmpty(disk.LogStorageAccountId))
                        {
                            throw new PSArgumentException(
                                      string.Format(
                                          Properties.Resources.InvalidPrimaryStagingAzureStorageAccountIdDiskInput,
                                          disk.VhdUri));
                        }

                        if (string.IsNullOrEmpty(disk.RecoveryAzureStorageAccountId))
                        {
                            throw new PSArgumentException(
                                      string.Format(
                                          Properties.Resources.InvalidRecoveryAzureStorageAccountIdDiskInput,
                                          disk.VhdUri));
                        }

                        a2aSwitchInput.VmDisks.Add(new A2AVmDiskInputDetails
                        {
                            DiskUri = disk.VhdUri,
                            RecoveryAzureStorageAccountId       = disk.RecoveryAzureStorageAccountId,
                            PrimaryStagingAzureStorageAccountId =
                                disk.LogStorageAccountId
                        });
                    }
                }

                input.Properties.ProviderSpecificDetails = a2aSwitchInput;
            }

            var response =
                RecoveryServicesClient.StartSwitchProtection(
                    this.fabricName,
                    this.protectionContainerName,
                    input);

            var jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(
                    PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse));
        }