public/Invoke-FootballCompetitionArtifactAutomation.ps1

function Invoke-FootballCompetitionArtifactAutomation {
    <#
        .SYNOPSIS
            Invokes fixture artifact automation.
 
        .EXAMPLE
            Invoke-FootballCompetitionArtifactAutomation -Header $Headers `
                                                         -Token $Token `
                                                         -DateMonth 2 `
                                                         -DateYear 2025 `
                                                         -Path C:\sportsmonk
         
        .EXAMPLE
            Invoke-FootballCompetitionArtifactAutomation -Header $Headers `
                                                         -Token $Token `
                                                         -Competition eng-premier `
                                                         -DateMonth 2 `
                                                         -DateYear 2025 `
                                                         -Path C:\sportsmonK
 
        .INPUTS
            - [Object] Header
     
    #>

    [CmdletBinding()]
    param(

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

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

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [int]$DateMonth,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [int]$DayToEnd,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [int]$DayToStart,

        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [int]$DateYear,

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

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

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

    )
    process{

        $ErrorActionPreference = 'Stop'

        # Get the competitions
        $Competitions = Select-FootballCompetition -Continent $Continent
        $Competitions.GetEnumerator() | ForEach-Object -Process {

            Write-Warning -Message "Processing $_."
            $CompetitionMatched = $false

            if ($($PSBoundParameters.ContainsKey('Competition'))) {

                if ($($_.Key) -eq $Competition) {
                
                    $CompetitionsToUse = $($_.Key)
                    $CompetitionMatched = $true

                }
      
            }
            else {

                $CompetitionsToUse = $($_.Key)
                $CompetitionMatched = $true
                
            } # if

            if ($CompetitionMatched) {

                $DaysInMonth = [DateTime]::DaysInMonth($DateYear,$DateMonth)

                for ($Day = 1; $Day -le $DaysInMonth; $Day++) {

                    if ($Day -le $DayToStart -or $Day -gt $DayToEnd) {

                        Write-Warning -Message "Day is $Day."
                        Write-Warning -Message "DayToStart is $DayToEnd."
                        Write-Warning -Message "DayToStart is $DayToStart."
                        continue

                    } # if

                    $Date = Get-Date -Year $DateYear -Month $DateMonth -Day $Day
                    $DateFormatted = $Date.ToString("yyyy-MM-dd")

                    New-FootballFixtureFolder -Competition $CompetitionsToUse -Date $DateFormatted -Path $Path

                    New-FootballFixutreFile -Competition $CompetitionsToUse -Type match-analysis -Date $DateFormatted -Path $Path

                    New-FootballFixutreFile -Competition $CompetitionsToUse -Type match-card-code -Date $DateFormatted -Path $Path

                    New-FootballFixutreFile -Competition $CompetitionsToUse -Type twitter-summary-code -Date $DateFormatted -Path $Path

                    Get-FootballFixtureCommentary -Header $Headers -Token $Token -Competition $CompetitionsToUse -Date $DateFormatted -Path $Path

                    Rename-FootballFixtureArtifact -Competition $CompetitionsToUse -Date $DateFormatted -Path $Path

                } # foreach

            } # if
    
        } # foreach-object

    } # process

} # function