access-requests/src/PSSailpoint.AccessRequests/Model/AccountsSelectionRequest.ps1

#
# Identity Security Cloud API - Access Requests
# Use these APIs to interact with the Identity Security Cloud platform to achieve repeatable, automated processes with greater scalability. We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs.
# Version: v1
# Generated by OpenAPI Generator: https://openapi-generator.tech
#

<#
.SYNOPSIS

No summary available.

.DESCRIPTION

Prefetch account selections for an access request before submit. Machine identity accounts-selection must use `requestedForWithRequestedItems` with `identityType: MACHINE` on each entry and only `ENTITLEMENT` items. Flat `requestedFor` / `requestedItems` must be omitted (do not send an empty array) for machine requests.

.PARAMETER RequestedFor
A list of Identity IDs for whom the Access is requested. * Must be omitted (do not send an empty array) when using `requestedForWithRequestedItems` (including all machine identity requests).
.PARAMETER RequestType
No description available.
.PARAMETER RequestedItems
Access items requested. * Must be omitted (do not send an empty array) when using `requestedForWithRequestedItems`.
.PARAMETER ClientMetadata
Arbitrary key-value pairs. They will never be processed by the IdentityNow system but will be returned on associated APIs such as /account-activities.
.PARAMETER RequestedForWithRequestedItems
Nested payload pairing each identity with its requested items. * Required for machine identity accounts-selection. Set `identityType: MACHINE` on each entry. * Machine requests support `ENTITLEMENT` items only and do not allow mixed human and machine identities. * When present, `requestedFor` and `requestedItems` must be omitted (do not send an empty array).
.OUTPUTS

AccountsSelectionRequest<PSCustomObject>
#>


function Initialize-AccountsSelectionRequest {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String[]]
        ${RequestedFor},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [ValidateSet("GRANT_ACCESS", "REVOKE_ACCESS", "MODIFY_ACCESS", "")]
        [PSCustomObject]
        ${RequestType},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${RequestedItems},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [System.Collections.Hashtable]
        ${ClientMetadata},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${RequestedForWithRequestedItems}
    )

    Process {
        'Creating PSCustomObject: PSSailpoint.AccessRequests => AccountsSelectionRequest' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        if (!$RequestedItems -and $RequestedItems.length -gt 25) {
            throw "invalid value for 'RequestedItems', number of items must be less than or equal to 25."
        }

        if (!$RequestedItems -and $RequestedItems.length -lt 1) {
            throw "invalid value for 'RequestedItems', number of items must be greater than or equal to 1."
        }


        $PSO = [PSCustomObject]@{
            "requestedFor" = ${RequestedFor}
            "requestType" = ${RequestType}
            "requestedItems" = ${RequestedItems}
            "clientMetadata" = ${ClientMetadata}
            "requestedForWithRequestedItems" = ${RequestedForWithRequestedItems}
        }

        return $PSO
    }
}

<#
.SYNOPSIS

Convert from JSON to AccountsSelectionRequest<PSCustomObject>

.DESCRIPTION

Convert from JSON to AccountsSelectionRequest<PSCustomObject>

.PARAMETER Json

Json object

.OUTPUTS

AccountsSelectionRequest<PSCustomObject>
#>

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

    Process {
        'Converting JSON to PSCustomObject: PSSailpoint.AccessRequests => AccountsSelectionRequest' | Write-Debug
        $PSBoundParameters | Out-DebugParameter | Write-Debug

        $JsonParameters = ConvertFrom-Json -InputObject $Json

        # check if Json contains properties not defined in AccountsSelectionRequest
        $AllProperties = ("requestedFor", "requestType", "requestedItems", "clientMetadata", "requestedForWithRequestedItems")
        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 "requestedFor"))) { #optional property not found
            $RequestedFor = $null
        } else {
            $RequestedFor = $JsonParameters.PSobject.Properties["requestedFor"].value
        }

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

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

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

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

        $PSO = [PSCustomObject]@{
            "requestedFor" = ${RequestedFor}
            "requestType" = ${RequestType}
            "requestedItems" = ${RequestedItems}
            "clientMetadata" = ${ClientMetadata}
            "requestedForWithRequestedItems" = ${RequestedForWithRequestedItems}
        }

        return $PSO
    }

}