KeyVault.Autorest/custom/Get-ParameterForRegion.cs

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
 
namespace Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Cmdlets
{
    using static Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.Extensions;
    using Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.PowerShell;
    using Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.Cmdlets;
    using System;
    using System.Management.Automation;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
 
    [global::Microsoft.Azure.PowerShell.Cmdlets.KeyVault.InternalExport]
    [global::System.Management.Automation.Cmdlet(global::System.Management.Automation.VerbsCommon.Get, @"ParameterForRegion")]
    [global::System.Management.Automation.OutputType(typeof(Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.IManagedHsm))]
    [global::Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Description(@"Create an in-memory object for parameter region.")]
    [global::Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Generated]
    public partial class GetAzKeyVaultManagedHsmRegionObject : global::System.Management.Automation.PSCmdlet
    {
        /// <summary>Backing field for <see cref="Parameter" /> property.</summary>
        private Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.IManagedHsm _parameter;
 
        /// <summary>Resource information with extended details.</summary>
        [global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Resource information with extended details.", ValueFromPipeline = true)]
        [Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.Info(
        Required = true,
        ReadOnly = false,
        Description = @"Resource information with extended details.",
        SerializedName = @"parameters",
        PossibleTypes = new[] { typeof(Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.IManagedHsm) })]
        [global::Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category(global::Microsoft.Azure.PowerShell.Cmdlets.KeyVault.ParameterCategory.Body)]
        public Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.IManagedHsm Parameter { get => this._parameter; set => this._parameter = value; }
 
        /// <summary>Backing field for <see cref="Region" /> property.</summary>
        private string[] _region;
 
        /// <summary>
        /// List of all regions associated with the managed hsm pool.
        /// </summary>
        [global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "List of all regions associated with the managed hsm pool.")]
        [Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Runtime.Info(
        Required = true,
        ReadOnly = false,
        Description = @"List of all regions associated with the managed hsm pool.",
        PossibleTypes = new[] { typeof(string) })]
        [global::Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Category(global::Microsoft.Azure.PowerShell.Cmdlets.KeyVault.ParameterCategory.Path)]
        public string[] Region { get => this._region; set => this._region = value; }
 
        [global::System.Management.Automation.Parameter(Mandatory = false, HelpMessage = "Specify if add or remove regions to existing regions")]
        public SwitchParameter RemoveRegion;
 
        /// <summary>Performs execution of the command.</summary>
        protected override void ProcessRecord()
        {
            if (RemoveRegion.IsPresent)
            {
                var remainingRegions = this.Parameter.Region?.Where(r => !this.Region.Contains(r.Name, StringComparer.OrdinalIgnoreCase));
                this.Parameter.Region = remainingRegions?.ToList();
            }
            else
            {
                foreach (var r in this.Region)
                {
                    this.Parameter.Region.Add(new Microsoft.Azure.PowerShell.Cmdlets.KeyVault.Models.MhsmGeoReplicatedRegion(new Dictionary<string, string>{{ "Name", r }}));
 
                }
            }
            WriteObject(this.Parameter);
        }
 
    }
}