public/Get-FootballFixtureResult.ps1

function Get-FootballFixtureResult {

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Competition,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Date,

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

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

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Path,

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

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            # Confirm the status of the csv containing the results.
            $RetrieveFixtureResult = Confirm-FootballFixtureResult -Competition $Competition -Date $Date -Path $Path

            if ($RetrieveFixtureResult) {

                # Test if the folder exists.
                # C:\sportsmonk\sportsmonk-results\ger-bundesliga\2024-12-08
                $PredictionResultPath = "$Path\sportsmonk-results"
                $PathExists = Test-Path -Path "$PredictionResultPath\$Competition\$Date"

                if (!$PathExists) {

                    New-Item -Path "$PredictionResultPath\$Competition\$Date" -ItemType Directory

                } # if

                # Set the export path for the csv containing the results.
                $ExportPath = "$PredictionResultPath\$Competition\$Date\$Competition-$Date.csv"

                # Get the results for the fixtures.
                $FixtureResults = Get-FixtureResult -FixtureList $FixtureList -PredictionObject $FixtureListPrediction

                if ($($FixtureResults.Count) -ge 1) {

                    $FixtureResults | Export-Csv -Path $ExportPath -Force -Verbose

                }
                else {

                    Write-Warning -Message "Result count: $($FixtureResults.Count)."

                } # if

            } # if
            
        }
        catch {

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

        } # trycatch
            
    } # process

} # function