Public/Training/Get-KB4TrainingStorePurchase.ps1

<#
.SYNOPSIS
Gets KnowBe4 training store purchases.

.DESCRIPTION
Retrieves training store purchases from the KnowBe4 Reporting API. Without Id,
the command returns a page of store purchases or all store purchases when All is
specified. With Id, the command returns a specific store purchase.

Normal output unwraps KnowBe4 page data and returns store purchase objects. Use
Raw to inspect the full response envelope and page wrapper.

.PARAMETER Id
The KnowBe4 training store purchase ID. This parameter also accepts the alias
StorePurchaseId.

.PARAMETER All
Retrieves all available pages.

.PARAMETER PageSize
The number of store purchases to request per page. Valid range is 1 through 500.

.PARAMETER Page
The page number to request when using page-based pagination.

.PARAMETER Cursor
The cursor value to request. Use 'true' to start cursor pagination manually.

.PARAMETER UsePagePagination
Uses page-based pagination when All is specified. Cursor pagination is preferred.

.PARAMETER Raw
Returns the full PSKB4Reporting response envelope instead of unwrapped store purchase
objects.

.EXAMPLE
Get-KB4TrainingStorePurchase -PageSize 50

Gets the first page of training store purchases.

.EXAMPLE
Get-KB4TrainingStorePurchase -Id 12345

Gets a specific training store purchase.

.OUTPUTS
PSCustomObject.
#>

function Get-KB4TrainingStorePurchase
{
    [CmdletBinding(DefaultParameterSetName = 'List')]
    param(
        [Parameter(Mandatory, ParameterSetName = 'ById', ValueFromPipelineByPropertyName)]
        [Alias('StorePurchaseId')]
        [int] $Id,

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

        [Parameter(ParameterSetName = 'List')]
        [ValidateRange(1, 500)]
        [int] $PageSize = 100,

        [Parameter(ParameterSetName = 'List')]
        [ValidateRange(1, [int]::MaxValue)]
        [int] $Page,

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

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

        [Parameter()]
        [switch] $Raw
    )

    process
    {
        if ($PSCmdlet.ParameterSetName -eq 'ById')
        {
            $path = '/v1/training/store_purchases/{0}' -f (Format-KB4PathValue -Value $Id)
            return Get-KB4ResponseBody -Response (Invoke-KB4Request -Path $path) -Raw:$Raw
        }

        $pagedParameters = @{
            Path              = '/v1/training/store_purchases'
            All               = $All
            PageSize          = $PageSize
            UsePagePagination = $UsePagePagination
            Raw               = $Raw
        }
        if ($PSBoundParameters.ContainsKey('Page'))
        {
            $pagedParameters['Page'] = $Page
        }
        if ($PSBoundParameters.ContainsKey('Cursor'))
        {
            $pagedParameters['Cursor'] = $Cursor
        }

        Invoke-KB4PagedRequest @pagedParameters
    }
}