machine-account-creation-request/src/PSSailpoint.MachineAccountCreationRequest/Model/MachineAccountCreateRequestInputV2.ps1

#
# SailPoint Identity Security API - Machine Account Creation Request
# Use these APIs to interact with the SailPoint Identity Security 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

Machine account create request. `sourceId` is required while tiered subtype configuration is enabled and is ignored when that flag is off. `entitlements` is honored while per-entitlement request details are enabled. `entitlementIds` is honored while that flag is off. A non-empty list of the kind the current flag state does not honor is rejected.

.PARAMETER SourceId
Source the machine account is created on. Required while tiered subtype configuration is enabled, so a connector-tier subtype can name its source. Ignored when that flag is off; the source is then the subtype's own source.
.PARAMETER SubtypeId
Subtype that must be in the source effective set and for which the caller holds the create machine account entitlement.
.PARAMETER FormId
Form selected for the machine account create request.
.PARAMETER OwnerIdentityId
Identity assigned as owner of the created machine account.
.PARAMETER MachineIdentityId
Machine identity to correlate with the created machine account. When omitted, a new machine identity is created.
.PARAMETER Environment
Environment type to use for the machine account.
.PARAMETER Description
Description for the machine account.
.PARAMETER UserInput
Fields of the form linked to the subtype in approval settings.
.PARAMETER Entitlements
Entitlements to provision, including an optional comment and access dates. Honored while per-entitlement request details are enabled. De-duplicated by `id` (first occurrence wins), at most 20 unique ids. A non-empty array is rejected when that flag is off. An empty array is accepted.
.PARAMETER EntitlementIds
Entitlement ids to provision. Honored while per-entitlement request details are off. Values are trimmed, blanks are dropped, and ids are de-duplicated (first occurrence wins), at most 20 unique ids. A non-empty array is rejected when per-entitlement request details are enabled. An empty array is accepted.
.OUTPUTS

MachineAccountCreateRequestInputV2<PSCustomObject>
#>


function Initialize-MachineAccountCreateRequestInputV2 {
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${SourceId} = "",
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${SubtypeId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${FormId} = "",
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${OwnerIdentityId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${MachineIdentityId},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${Environment} = "",
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String]
        ${Description} = "",
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject]
        ${UserInput},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [PSCustomObject[]]
        ${Entitlements},
        [Parameter(ValueFromPipelineByPropertyName = $true)]
        [String[]]
        ${EntitlementIds}
    )

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

        if (!$SubtypeId) {
            throw "invalid value for 'SubtypeId', 'SubtypeId' cannot be null."
        }

        if (!$OwnerIdentityId) {
            throw "invalid value for 'OwnerIdentityId', 'OwnerIdentityId' cannot be null."
        }


        $PSO = [PSCustomObject]@{
            "sourceId" = ${SourceId}
            "subtypeId" = ${SubtypeId}
            "formId" = ${FormId}
            "ownerIdentityId" = ${OwnerIdentityId}
            "machineIdentityId" = ${MachineIdentityId}
            "environment" = ${Environment}
            "description" = ${Description}
            "userInput" = ${UserInput}
            "entitlements" = ${Entitlements}
            "entitlementIds" = ${EntitlementIds}
        }

        return $PSO
    }
}

<#
.SYNOPSIS

Convert from JSON to MachineAccountCreateRequestInputV2<PSCustomObject>

.DESCRIPTION

Convert from JSON to MachineAccountCreateRequestInputV2<PSCustomObject>

.PARAMETER Json

Json object

.OUTPUTS

MachineAccountCreateRequestInputV2<PSCustomObject>
#>

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

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

        $JsonParameters = ConvertFrom-Json -InputObject $Json

        # check if Json contains properties not defined in MachineAccountCreateRequestInputV2
        $AllProperties = ("sourceId", "subtypeId", "formId", "ownerIdentityId", "machineIdentityId", "environment", "description", "userInput", "entitlements", "entitlementIds")
        foreach ($name in $JsonParameters.PsObject.Properties.Name) {
            if (!($AllProperties.Contains($name))) {
                throw "Error! JSON key '$name' not found in the properties: $($AllProperties)"
            }
        }

        If ([string]::IsNullOrEmpty($Json) -or $Json -eq "{}") { # empty json
            throw "Error! Empty JSON cannot be serialized due to the required property 'subtypeId' missing."
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "subtypeId"))) {
            throw "Error! JSON cannot be serialized due to the required property 'subtypeId' missing."
        } else {
            $SubtypeId = $JsonParameters.PSobject.Properties["subtypeId"].value
        }

        if (!([bool]($JsonParameters.PSobject.Properties.name -match "ownerIdentityId"))) {
            throw "Error! JSON cannot be serialized due to the required property 'ownerIdentityId' missing."
        } else {
            $OwnerIdentityId = $JsonParameters.PSobject.Properties["ownerIdentityId"].value
        }

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

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

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

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

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

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

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

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

        $PSO = [PSCustomObject]@{
            "sourceId" = ${SourceId}
            "subtypeId" = ${SubtypeId}
            "formId" = ${FormId}
            "ownerIdentityId" = ${OwnerIdentityId}
            "machineIdentityId" = ${MachineIdentityId}
            "environment" = ${Environment}
            "description" = ${Description}
            "userInput" = ${UserInput}
            "entitlements" = ${Entitlements}
            "entitlementIds" = ${EntitlementIds}
        }

        return $PSO
    }

}