public/Get-FootballCompetitionStageStatistic.ps1

function Get-FootballCompetitionStageStatistic {
    <#
        .SYNOPSIS
            Get-FootballCompetitionStageStatistic -Header $Headers -Token $Token -StageId 77471288
 
        .LINK
            https://docs.sportmonks.com/football/definitions/types/statistics
         
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [Object]$Header,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [int]$StageId,

        [Parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [int]$SeasonId,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Token

    )
    process{

        $ErrorActionPreference

        try {

            if ($($PSBoundParameters.ContainsKey('StageId')) -and !$($PSBoundParameters.ContainsKey('SeasonId'))) {

                $TypeUri = "https://api.sportmonks.com/v3/football/statistics/stages/$($StageId)?api_token=$Token&include=type"
                $TypeResponse = Invoke-RestMethod $TypeUri -Method 'GET' -Headers $Header
                $($TypeResponse.data)

            } # if

            if ($($PSBoundParameters.ContainsKey('SeasonId')) -and !$($PSBoundParameters.ContainsKey('StageId'))) {

                $TypeUri = "https://api.sportmonks.com/v3/football/stages/seasons/$($SeasonId)?api_token=$Token&include=type;statistics.type"
                $TypeResponse = Invoke-RestMethod $TypeUri -Method 'GET' -Headers $Header
                $($TypeResponse.data.statistics)

            } # if

        }
        catch {

            "$($MyInvocation.MyCommand.Name): $_.Exception.Message"

        } # try catch
  
    } # process

} # function