Public/ChangeLog/Set-R1ChangeLogSetting.ps1

# .ExternalHelp psRadiantOne-help.xml
function Set-R1ChangeLogSetting {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    [OutputType([void])]
    param(
        [parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [bool]$enableChangelog,

        [parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [ValidateRange(0, 365)]
        [int]$maxAge,

        [parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [ValidateSet('all', 'error', 'status')]
        [string]$persistentCacheRefreshLog,

        [parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [hashtable[]]$changelogs
    )

    Begin {

        Assert-R1Session -RequireToken

    }#begin

    Process {

        $URI = Resolve-R1ServiceUrl -Service Settings -Path 'change_log/settings'

        #Retrieve the current settings and send them back with the supplied values applied over
        #them, so a setting left unspecified keeps its current value.
        $Existing = Get-R1ChangeLogSetting

        $Template = [ordered]@{
            enableChangelog           = $true
            maxAge                    = 3
            persistentCacheRefreshLog = 'all'
            changelogs                = @()
        }

        $Request = Merge-R1Parameter -Template $Template -BoundParameter ($PSBoundParameters | Get-Parameter) -Fallback $Existing

        foreach ($Collection in 'changelogs') {

            $Request[$Collection] = @($Request[$Collection])

        }

        $Body = $Request | ConvertTo-R1JsonBody -EmptyArrayProperty changelogs

        if ($PSCmdlet.ShouldProcess($Script:psRadiantOneSession.BaseURI, 'Update Change Log Settings')) {

            $null = Invoke-R1RestMethod -Uri $URI -Method PUT -Body $Body

        }

    }#process

    End { }#end

}