Model/MessageApproval.ps1

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

<#
MessageApproval<PSCustomObject>
#>


function New-MessageApproval {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${Moderators},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${PredefinedModerators},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${BypassModerationFromSendersOrMembers},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${PredefinedBypassModerationFromSendersOrMembers},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${ActivityId}
    )

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

        
        $PSO = [PSCustomObject]@{
            "Moderators" = ${Moderators}
            "PredefinedModerators" = ${PredefinedModerators}
            "BypassModerationFromSendersOrMembers" = ${BypassModerationFromSendersOrMembers}
            "PredefinedBypassModerationFromSendersOrMembers" = ${PredefinedBypassModerationFromSendersOrMembers}
            "ActivityId" = ${ActivityId}
        }

        return $PSO
    }
}

<#
MessageApproval<PSCustomObject>
#>

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

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

        $JsonParameters = ConvertFrom-Json -InputObject $Json

        # check if Json contains properties not defined in MessageApproval
        $AllProperties = $("Moderators", "PredefinedModerators", "BypassModerationFromSendersOrMembers", "PredefinedBypassModerationFromSendersOrMembers", "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 "Moderators"))) { #optional property not found
            $Moderators = $null
        } else {
            $Moderators = $JsonParameters.PSobject.Properties["Moderators"].value
        }

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

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

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

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

        $PSO = [PSCustomObject]@{
            "Moderators" = ${Moderators}
            "PredefinedModerators" = ${PredefinedModerators}
            "BypassModerationFromSendersOrMembers" = ${BypassModerationFromSendersOrMembers}
            "PredefinedBypassModerationFromSendersOrMembers" = ${PredefinedBypassModerationFromSendersOrMembers}
            "ActivityId" = ${ActivityId}
        }

        return $PSO
    }

}