Public/Remove-DuneCollection.ps1

<#
.SYNOPSIS
Removes DuneCollection object.
.DESCRIPTION
Removes DuneCollection object.
.PARAMETER Name
Specifies the DuneCollection name.
.PARAMETER Id
Specifies the DuneCollection id.
.PARAMETER Collection
Specifies the DuneCollection object.
.PARAMETER IncludeChildren
Specifies whether all Deployments, ResourceGroup and Resources belonging to that Collection are deleted as well.
.INPUTS
DuneCollection object.
.OUTPUTS
Invoke-WebRequest output.
.EXAMPLE
> Remove-DuneCollection -Name foo
.EXAMPLE
> Get-DuneCollection foo | Remove-DuneCollection
.EXAMPLE
> Get-DuneCollection foo | Remove-DuneCollection -IncludeChildren
.LINK
https://gitlab.com/yendico1/products/starburst/backend-workflow/ps-modules/starburst/-/blob/main/Starburst/Public/Remove-DuneCollection.ps1
#>

function Remove-DuneCollection {
    [CmdletBinding(
        SupportsShouldProcess,
        DefaultParameterSetName = 'Id',
        ConfirmImpact = 'High'
    )]
    param (
        [Parameter(Mandatory, ParameterSetName = "Name", Position = 0)]
        [string]$Name,

        [Parameter(Mandatory, ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(ParameterSetName = "Collection", ValueFromPipeline, Mandatory)]
        [DuneCollection]$Collection,

        [Parameter()]
        [switch]$IncludeChildren,

        [Parameter()]
        [switch]$HardDelete
    )

    begin {
        Write-Debug "$($MyInvocation.MyCommand)|begin"
        $Uri = "collections"
    }

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"
        switch ($PSCmdlet.ParameterSetName) {
            'Name' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Name)"
                $Collection = Get-DuneCollection -Name $Name
            }
            'Id' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Id)"
                $Collection = Get-DuneCollection -Id $Id
            }
            'Collection' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Collection.Id)"
            }
            Default {
                return
            }
        }
        $Url = $("{0}/{1}" -f $Uri, $Collection.Id)
        if ($PSCmdlet.ShouldProcess($Collection.Name)) {
            if ($IncludeChildren) {
                $Collection | Get-DuneDeployment | Remove-DuneDeployment -IncludeChildren
            }
            if ($HardDelete) { $Url = $Url, "HardDelete=1" -join "?" }
            $Null = Invoke-DuneApiRequest $Url -Method DELETE
        }
    }

    end {
        Write-Debug "$($MyInvocation.MyCommand)|end"
    }
}