Public/ElectronicVault/Get-UKGElectronicVaultOption.ps1

function Get-UKGElectronicVaultOption {
    <#
    .SYNOPSIS
        Gets electronic vault options from the UKG HR Service Delivery API.

    .DESCRIPTION
        Retrieves electronic vault option configurations by ID or lists all.

    .PARAMETER Id
        The unique identifier of the vault option to retrieve.

    .PARAMETER All
        Retrieves all electronic vault options.

    .PARAMETER PerPage
        Number of results per page (1-100, default 25).

    .PARAMETER Cursor
        Pagination cursor for retrieving a specific page.

    .EXAMPLE
        Get-UKGElectronicVaultOption -Id "evo123"

    .EXAMPLE
        Get-UKGElectronicVaultOption -All

    .OUTPUTS
        UKG.ElectronicVaultOption or array of UKG.ElectronicVaultOption objects.
    #>

    [CmdletBinding(DefaultParameterSetName = 'ById')]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory, ParameterSetName = 'ById', ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [Alias('VaultOptionId')]
        [string]$Id,

        [Parameter(ParameterSetName = 'List')]
        [switch]$All,

        [Parameter(ParameterSetName = 'List')]
        [ValidateRange(1, 100)]
        [int]$PerPage = 25,

        [Parameter(ParameterSetName = 'List')]
        [string]$Cursor
    )

    process {
        $queryParams = @{}

        switch ($PSCmdlet.ParameterSetName) {
            'ById' {
                $response = Invoke-UKGRequest -Endpoint "/electronic_vault_options/$Id" -Method GET
                if ($response) {
                    $response.PSObject.TypeNames.Insert(0, 'UKG.ElectronicVaultOption')
                }
                return $response
            }

            'List' {
                $queryParams['per_page'] = $PerPage
                if ($Cursor) { $queryParams['cursor'] = $Cursor }

                if ($All -and -not $Cursor) {
                    $allOptions = Get-UKGAllPages -Endpoint '/electronic_vault_options' -Method GET -QueryParameters $queryParams
                    foreach ($opt in $allOptions) {
                        $opt.PSObject.TypeNames.Insert(0, 'UKG.ElectronicVaultOption')
                    }
                    return $allOptions
                }
                else {
                    $response = Invoke-UKGRequest -Endpoint '/electronic_vault_options' -Method GET -QueryParameters $queryParams -ReturnHeaders
                    if ($response.Data) {
                        foreach ($opt in $response.Data) {
                            $opt.PSObject.TypeNames.Insert(0, 'UKG.ElectronicVaultOption')
                        }
                        return $response.Data
                    }
                }
            }
        }
    }
}

function Set-UKGElectronicVaultOption {
    <#
    .SYNOPSIS
        Updates an electronic vault option in the UKG HR Service Delivery system.

    .DESCRIPTION
        Updates electronic vault option configuration using PATCH.

    .PARAMETER Id
        The unique identifier of the vault option to update.

    .PARAMETER Enabled
        Whether the vault option is enabled.

    .PARAMETER Properties
        Hashtable of properties to update.

    .PARAMETER InputObject
        A hashtable or PSCustomObject containing the properties to update.

    .EXAMPLE
        Set-UKGElectronicVaultOption -Id "evo123" -Enabled $true

    .EXAMPLE
        Set-UKGElectronicVaultOption -Id "evo123" -Properties @{ enabled = $true; auto_invite = $false }

    .OUTPUTS
        UKG.ElectronicVaultOption object representing the updated option.
    #>

    [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'Properties')]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [Alias('VaultOptionId')]
        [string]$Id,

        [Parameter(ParameterSetName = 'Properties')]
        [bool]$Enabled,

        [Parameter(ParameterSetName = 'Properties')]
        [hashtable]$Properties,

        [Parameter(Mandatory, ParameterSetName = 'InputObject')]
        [object]$InputObject
    )

    process {
        $body = @{}

        if ($InputObject) {
            if ($InputObject -is [hashtable]) {
                $body = $InputObject.Clone()
            }
            else {
                foreach ($prop in $InputObject.PSObject.Properties) {
                    if ($prop.Name -notin @('id', 'created_at', 'updated_at', 'PSTypeName')) {
                        $body[$prop.Name] = $prop.Value
                    }
                }
            }
        }
        else {
            if ($PSBoundParameters.ContainsKey('Enabled')) { $body['enabled'] = $Enabled }

            if ($Properties) {
                foreach ($key in $Properties.Keys) {
                    $body[$key] = $Properties[$key]
                }
            }
        }

        if ($body.Count -eq 0) {
            Write-Warning "No properties specified to update."
            return
        }

        if ($PSCmdlet.ShouldProcess($Id, 'Update Electronic Vault Option')) {
            $response = Invoke-UKGRequest -Endpoint "/electronic_vault_options/$Id" -Method PATCH -Body $body

            if ($response) {
                $response.PSObject.TypeNames.Insert(0, 'UKG.ElectronicVaultOption')
            }

            return $response
        }
    }
}