public/Invoke-PopulateFootballCompetitionTemplateAutomation.ps1

function Invoke-PopulateFootballCompetitionTemplateAutomation {
    <#
        .EXAMPLE
            Invoke-PopulateFootballCompetitionTemplateAutomation -Header $Headers -Token $Token -Continent north-america -Date 2025-02-25 -Type review -Path C:\sportsmonk
     
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateSet('australia','europe','europe-uk','europe-uk-cup','europe-uk-fl','europe-uk-wsl','south-america','north-america','asia')]
        [string]$Continent,

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

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

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

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

        [Parameter(Mandatory=$true)]
        [ValidateSet('preview','review')]
        [string]$Type

    )
    process{

        $ErrorActionPreference = 'Stop'
        
        $Competions = Select-FootballCompetition -Continent $Continent
        $Competions.GetEnumerator() | ForEach-Object -Process {

            $Prompt1 = Read-UserInput -Title $($MyInvocation.MyCommand.Name) -Message "Create templates $($_.Key) - $Date."

            if ($Prompt1 -eq 1) {

                Write-Warning -Message "Skipping $($_.Key) - $Date."

            }
            else {

                $ResultsPathExists = $false
                $PredictionsPathExists = $false
                $ResultsPathExists = Test-Path -Path "$Path\sportsmonk-results\$($_.Key)\$Date"
                $PredictionsPathExists = Test-Path -Path "$Path\sportsmonk-predictions\$($_.Key)\$Date"

                if ($PredictionsPathExists) {

                    New-FootballFixtureFolder -Competition $($_.Key) -Date $Date -Path $Path
                    # Must run before Get-FootballFixturePredictionPreviewData.
                    Get-FootballFixturePredictedScoreCardData -Competition $($_.Key) -Date $Date -Path $Path
                    Get-FootballFixturePredictionPreviewData -Header $Header -Token $Token -Competition $($_.Key) -Date $Date -Path $Path

                } # if

                if ($Type -eq 'preview' -and $PredictionsPathExists) {

                    Get-FootballFixtureMarketTypeProbabilityPercentage -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Preview -Path $Path
                    Update-FootballFixtureTemplate -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Template prediction-preview -Path $Path
                    Update-FootballFixtureTemplate -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Template prediction-corner-preview -Path $Path

                } # if

                if ($Type -eq 'review' -and $ResultsPathExists -and $PredictionsPathExists) {

                    Get-FootballFixtureMarketTypeProbabilityPercentage -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Path $Path
                    Update-FootballFixtureTemplate -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Template prediction-review -Path $Path
                    Update-FootballFixtureTemplate -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Template prediction-corner-review -Path $Path
                    Update-FootballFixtureTemplate -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Template prediction-goal-review -Path $Path
                    Update-FootballFixtureTemplate -Header $Header -Token $Token -Date $Date -Competition $($_.Key) -Template outcome -Path $Path

                } # if

            } # if

        } # foreach-object

    } # process

} # function