Public/Get-CriteriaCollection.ps1

<#
.SYNOPSIS
    Gets criteria collections from the Fortytwo Collections API.

.DESCRIPTION
    This function retrieves criteria collections from the Fortytwo Collections API. It supports pagination to handle large result sets.
#>

function Get-CriteriaCollection {
    [CmdletBinding(DefaultParameterSetName = "Default")]
    param (
        [Parameter(Mandatory = $true, ParameterSetName = "Single")]
        [ValidatePattern("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$", ErrorMessage = "Id must be a valid GUID.")] # Is a guid connector object id
        [string] $Id,
        [Parameter(Mandatory = $true, ParameterSetName = "Collection", ValueFromPipeline = $true)]
        [System.Collections.Hashtable] $Collection
    )

    process {
        if (-not $Script:APIRoot -or -not $Script:AccessTokenProfile) {
            throw "Not connected to Fortytwo Collections. Please run Connect-Collections first."
        }

        if ($PSCmdlet.ParameterSetName -eq "Collection") {
            if (-not $Collection.ContainsKey("id") -or [string]::IsNullOrEmpty($Collection.id)) {
                throw "The collection object must contain a valid 'id' property."
            }
            $Id = $Collection.id
        }

        if ($PSCmdlet.ParameterSetName -eq "Single" -or $PSCmdlet.ParameterSetName -eq "Collection") {
            Write-Verbose "Getting Criteria Collection with Id: $Id"
            Get-CollectionObject -CollectionType "collections-criteria" -Id $Id
        }
        else {
            Get-CollectionObject -CollectionType "collections-criteria"
        }
    }
}