public/Confirm-FootballFixtureArtifact.ps1

function Confirm-FootballFixtureArtifact {
    <#
        .EXAMPLE
            Confirm-FootballFixtureArtifact -Type preview -Path C:\sportsmonk
 
        .EXAMPLE
            Confirm-FootballFixtureArtifact -Type review -Path C:\sportsmonk
 
    #>

    [CmdletBinding()]
    param(

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

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

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            if ($Type -like '*-image') {

                $CompetitionFolders = Get-ChildItem -Path "$Path\fixture-artifact\working-set"
                $FolderFilter = 'working-set'

            } # if


            if ($Type -like '*template') {

                $CompetitionFolders = Get-ChildItem -Path "$Path\fixture-artifact\multi-media"
                $FolderFilter = 'multi-media'

            } # if

            foreach ($CompetitionFolder in $CompetitionFolders) {

                # \sportsmonk\fixture-artifact\working-set\usa-mls
                $Competition = $($CompetitionFolder.FullName).Split("$FolderFilter\")[1]
                $CompetitionName = Get-Competition -Name $Competition
                $FixtureFolders = Get-ChildItem -Path $($CompetitionFolder.FullName) -ErrorAction Stop

                foreach ($FixtureFolder in $FixtureFolders) {

                    # \sportsmonk\fixture-artifact\working-set\usa-mls\2025-02-23
                    $Date = $($FixtureFolder.FullName).Split("\$FolderFilter\$Competition\")[1]

                    $PSObject = [PSCustomObject]@{
                        FixtureFolderFullName = $($FixtureFolder.FullName).Split("$Path\")[1]
                        Competition = $Competition
                        CompetitionName = $CompetitionName
                        Date = $Date
                        Type = $Type
                    }

                    $PathExists = Test-Path -Path "$Path\sportsmonk-predictions\$Competition\$Date\$Competition-240-$Date.csv"

                    if (!$PathExists) {

                        continue
                        
                    } # if

                    # Count the fixtures
                    $FixturesToPlay = Import-Csv -Path "$Path\sportsmonk-predictions\$Competition\$Date\$Competition-240-$Date.csv"

                    if ($Type -eq 'review-image') {

                        $FixtureFiles = Get-ChildItem -Path $($FixtureFolder.FullName) -File -Filter '*.png' -Recurse -ErrorAction Stop `
                            | Where-Object {$_.FullName -like '*rev*' -and $_.FullName -notlike '*prev*'}

                        # 3 files per fixture
                        $CorrectTotal = (3 * $($FixturesToPlay.Count))

                        # Set default value
                        $IsCompleted = $false

                        if ($($FixtureFiles.Count) -eq $CorrectTotal) {

                            $IsCompleted = $true

                        } # if

                    } # if

                    if ($Type -eq 'review-template') {

                        $FixtureFiles = Get-ChildItem -Path $($FixtureFolder.FullName) -File -Include '*.txt','*.js' -Recurse -ErrorAction Stop `
                            | Where-Object {$_.FullName -like '*prediction*' -or $_.FullName -like '*rev*' -and $_.FullName -notlike '*prev*'}

                        # 6 files per fixture
                        $CorrectTotal = 6 * $($FixturesToPlay.Count)

                        # Set default value
                        $IsCompleted = $false

                        if ($($FixturesToPlay.Count) -eq 3 -and $($FixturesToPlay.Count) -lt 6) {
                            
                            # The outcomes
                            $CorrectTotal = $CorrectTotal + 1

                        } # if

                        if ($($FixturesToPlay.Count) -ge 6 -and $($FixturesToPlay.Count) -lt 9) {

                            # The outcomes
                            $CorrectTotal = $CorrectTotal + 2

                        } # if

                        if ($($FixturesToPlay.Count) -eq 9 -and $($FixturesToPlay.Count) -lt 12) {

                            # The outcomes
                            $CorrectTotal = $CorrectTotal + 3

                        } # if

                        if ($($FixturesToPlay.Count) -eq 12) {

                            # The outcomes
                            $CorrectTotal = $CorrectTotal + 4

                        } # if

                        if ($($FixtureFiles.Count) -eq $CorrectTotal) {

                            # The outcomes
                            $IsCompleted = $true

                        } # if

                    } # if

                    if ($Type -like 'preview*') {

                        $FixtureFiles = Get-ChildItem -Path $($FixtureFolder.FullName) -File -Recurse -ErrorAction Stop `
                            | Where-Object {$_.FullName -like "*prev*"}

                    } # if

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

                        $PSObject | Add-Member -MemberType NoteProperty -Name FixtureFilesCount -Value $($FixtureFiles.Count)
                        $PSObject | Add-Member -MemberType NoteProperty -Name CorrectFixtureFilesCount -Value $CorrectTotal
                        $PSObject | Add-Member -MemberType NoteProperty -Name FixturesToPlay -Value $($FixturesToPlay.Count)
                        $PSObject | Add-Member -MemberType NoteProperty -Name IsCompleted -Value $IsCompleted
                        $PSObject

                    } # if $CorrectTotal
            
                } # foreach
            
            } # foreach

        }
        catch {

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

    } # process

} # function