/// <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));
        }