public/Update-FootballCompetitionTemplate.ps1

function Update-FootballCompetitionTemplate {

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateSet('get-predictions','get-results')]
        [string]$Action,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [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]$PredictionDateRange,

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

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

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

    )
    process{

        $ErrorActionPreference = 'Stop'
        
        if ($Action -eq 'get-predictions') {

            Set-ActionState -Action get-predictions -Continent $Continent -Enabled true -DateRange $PredictionDateRange -Path $Path

            Invoke-SportsmonkAutomation -Header $Header -Token $Token -SMToken $SMToken -Action get-predictions -Path $Path

        } # if
    
        if ($Action -eq 'get-results') {
            
            Set-ActionState -Action get-results -Continent $Continent -Enabled true -DateRange $ResultDateRange -Path $Path
 
            Invoke-SportsmonkAutomation -Header $Header -Token $Token -SMToken $SMToken -Action get-results -Path $Path
    
            foreach ($DateToUse in $Date) {
        
                Set-ActionState -Action populate-templates -Continent $Continent -Enabled true -Date $DateToUse -Path $Path
                
                # Loop through twice for correct score issue
                $Count = 2
        
                for ($i = 0;$i -lt $Count; $i++) {
        
                    # Templates
                    Invoke-SportsmonkAutomation -Header $Header -Token $Token -SMToken $SMToken -Action populate-templates -Path $Path
        
                } # for
        
            } # foreach

        } # if

    } # process

} # function