Classes/Public/PrismCategory.ps1
|
class PrismCategory { [string]$ExtId [string]$Key [string]$Value [string]$Description [string]$Type [string]$OwnerUuid [string]$TenantId [string]$PrismSession [object[]]$Associations [object[]]$DetailedAssociations [object[]]$Links [object]$RawData PrismCategory() { # Preserve the previous Name property as a writable alias of Key. Add-Member -InputObject $this -MemberType AliasProperty -Name Name -Value Key } PrismCategory([string]$key, [string]$value) { $this.Key = $key $this.Value = $value Add-Member -InputObject $this -MemberType AliasProperty -Name Name -Value Key } PrismCategory([object]$data, [string]$prismSession) { if ($null -eq $data) { throw 'The API response did not contain category data.' } $this.PrismSession = $prismSession $this.RawData = $data foreach ($property in $this.psobject.Properties) { if ($property.Name -in @('PrismSession', 'RawData')) { continue } if ($data -is [System.Collections.IDictionary]) { if ($data.Contains($property.Name)) { $this.($property.Name) = $data[$property.Name] } } elseif ($data.psobject.Properties[$property.Name]) { $this.($property.Name) = $data.($property.Name) } } Add-Member -InputObject $this -MemberType AliasProperty -Name Name -Value Key } [hashtable] ToApiBody() { if ([string]::IsNullOrWhiteSpace($this.Key) -or [string]::IsNullOrWhiteSpace($this.Value)) { throw 'Category Key and Value are required.' } $body = @{ key = $this.Key; value = $this.Value } if ($null -ne $this.Description) { $body.description = $this.Description } if (-not [string]::IsNullOrWhiteSpace($this.OwnerUuid)) { $body.ownerUuid = $this.OwnerUuid } return $body } } |