public/Remove-ProcessedFixtureData.ps1

function Remove-ProcessedFixtureData {
    <#
        .EXAMPLE
            Remove-ProcessedFixtureData -Continent north-america -StartDate 2025-07-07 -Type predictions -Path C:\sportsmonk
         
        .EXAMPLE
            Remove-ProcessedFixtureData -Continent europe -StartDate 2025-05-01 -Type predictions -Reverse -Path C:\sportsmonk
 
     
    #>

    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]$StartDate,

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

        [Parameter(Mandatory=$false)]
        [switch]$Reverse,

        [Parameter(Mandatory=$true)]
        [ValidateSet('predictions','prediction-preview','results')]
        [string]$Type
        
    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            switch ($Type) {

                'prediction-preview' {

                    $BasePath = "$Path\fixture-artifact\$Type"

                }
                default {

                    $BasePath = "$Path\sportsmonk-$Type"

                }

            } # switch

            $Competions = Select-FootballCompetition -Continent $Continent
            $Competions | Format-Table
            $Competions.GetEnumerator() | ForEach-Object -Process {

                # Set variable
                $Competition = $($_.key)

                # Set path to use
                $PathToUse = "$BasePath\$Competition"
                
                # Test path
                $PathExists = Test-Path -Path $PathToUse -ErrorAction Stop

                if ($PathExists) {

                    # Get the dates
                    $CompetitionDate = (Get-ChildItem -Path $PathToUse -Exclude '*.csv' -ErrorAction Stop).Name

                    $Hash =@{
                        FunctionName = $($MyInvocation.MyCommand.Name)
                        Competition = $Competition
                        CompetitionDates = $($CompetitionDate.Count)
                        PathToUse = $PathToUse
                        PathExists = $PathExists
                    }

                    $Hash | Format-Table

                    foreach ($Date in $CompetitionDate) {

                        $DateToUse = Get-Date -Date $Date
                        $StartDateToUse = Get-Date -Date $StartDate

                        Write-Warning -Message "Comparing date to use: $DateToUse and StartDateToUse: $StartDateToUse"

                        if ($Reverse -and $DateToUse -le $StartDateToUse) {

                            Write-Warning "Processing: $Competition - $Date"
                            Remove-Item -Path "$PathToUse\$Date\" -Force -Recurse -Confirm:$false -Verbose -ErrorAction Stop

                        } # if

                        if (!$Reverse -and $DateToUse -ge $StartDateToUse) {

                            Write-Warning "Processing: $Competition - $Date"
                            Remove-Item -Path "$PathToUse\$Date\" -Force -Recurse -Confirm:$false -Verbose -ErrorAction Stop

                        } # if

                    } # foreach

                } # if

            } # foreach-object

        }
        catch {

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

        } # trycatch

    } # process

} # function