Model/EmailForward.ps1

#
# Cloud Governance Api
# Contact: support@avepoint.com
#

<#
EmailForward<PSCustomObject>
#>


function New-EmailForward {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [System.Nullable[Boolean]]
        ${EnableEmailForwarding} = $false,
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject]
        ${ConvertEmailForward} = "ForwardInternalEmail",
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject]
        ${ForwardInternalEmailAddress},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${ForwardExternalEmailAddress},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [System.Nullable[Boolean]]
        ${EnableDeliverMessage} = $false,
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${ActivityId}
    )

    Process {
        'Creating PSCustomObject: Cloud.Governance.Client => EmailForward' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        
        $PSO = [PSCustomObject]@{
            "EnableEmailForwarding" = ${EnableEmailForwarding}
            "ConvertEmailForward" = ${ConvertEmailForward}
            "ForwardInternalEmailAddress" = ${ForwardInternalEmailAddress}
            "ForwardExternalEmailAddress" = ${ForwardExternalEmailAddress}
            "EnableDeliverMessage" = ${EnableDeliverMessage}
            "ActivityId" = ${ActivityId}
        }

        return $PSO
    }
}

<#
EmailForward<PSCustomObject>
#>

function ConvertFrom-JsonToEmailForward {
    Param(
        [AllowEmptyString()]
        [string]$Json
    )

    Process {
        'Converting JSON to PSCustomObject: Cloud.Governance.Client => EmailForward' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $JsonParameters = ConvertFrom-Json -InputObject $Json

        # check if Json contains properties not defined in EmailForward
        $AllProperties = $("EnableEmailForwarding", "ConvertEmailForward", "ForwardInternalEmailAddress", "ForwardExternalEmailAddress", "EnableDeliverMessage", "ActivityId")
        foreach ($name in $JsonParameters.PsObject.Properties.Name) {
            if (!($AllProperties.Contains($name))) {
                throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
            }
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "EnableEmailForwarding"))) { #optional property not found
            $EnableEmailForwarding = $null
        } else {
            $EnableEmailForwarding = $JsonParameters.PSobject.Properties["EnableEmailForwarding"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "ConvertEmailForward"))) { #optional property not found
            $ConvertEmailForward = $null
        } else {
            $ConvertEmailForward = $JsonParameters.PSobject.Properties["ConvertEmailForward"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "ForwardInternalEmailAddress"))) { #optional property not found
            $ForwardInternalEmailAddress = $null
        } else {
            $ForwardInternalEmailAddress = $JsonParameters.PSobject.Properties["ForwardInternalEmailAddress"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "ForwardExternalEmailAddress"))) { #optional property not found
            $ForwardExternalEmailAddress = $null
        } else {
            $ForwardExternalEmailAddress = $JsonParameters.PSobject.Properties["ForwardExternalEmailAddress"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "EnableDeliverMessage"))) { #optional property not found
            $EnableDeliverMessage = $null
        } else {
            $EnableDeliverMessage = $JsonParameters.PSobject.Properties["EnableDeliverMessage"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "ActivityId"))) { #optional property not found
            $ActivityId = $null
        } else {
            $ActivityId = $JsonParameters.PSobject.Properties["ActivityId"].value
        }

        $PSO = [PSCustomObject]@{
            "EnableEmailForwarding" = ${EnableEmailForwarding}
            "ConvertEmailForward" = ${ConvertEmailForward}
            "ForwardInternalEmailAddress" = ${ForwardInternalEmailAddress}
            "ForwardExternalEmailAddress" = ${ForwardExternalEmailAddress}
            "EnableDeliverMessage" = ${EnableDeliverMessage}
            "ActivityId" = ${ActivityId}
        }

        return $PSO
    }

}