public/Confirm-ProcessedFootballFixtureMedia.ps1

function Confirm-ProcessedFootballFixtureMedia {
    <#
        .SYNOPSIS
            Confirm-ProcessedFootballFixtureMedia -Competition bra-seriea -Date 2025-04-06 -Content corners -Endpoint instagram -Path C:\sportsmonk
 
    #>

    [CmdletBinding()]
    param(

        [Parameter(Mandatory=$true)]
        [ValidateSet('corners','goals','match','outcomes')]
        [string]$Content,

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

        [Parameter(Mandatory=$true)]
        [ValidateSet('fbpost','fbstory','instagram','instagram-story')]
        [string]$Endpoint,

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

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

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            [int]$DateYear = $Date.Split('-')[0]
            [int]$DateMonth = $Date.Split('-')[1]
            $MLogPath = Get-ProcessedFootballFixtureFolderPath -Competition $Competition -DateYear $DateYear -DateMonth $DateMonth -Type media -Path $Path
            #$FilesToProcess = Get-ChildItem -Path $MLogPath | Where-Object {$_.FullName -like "*$Content-$Endpoint.json"}

            if ($Content -eq 'outcomes') {
                
                $FileCount = 0
                $ProcessedFiles =@()
                Write-Warning "Processing content $Content against endpoint $Endpoint."
                $FilesToProcess = Get-ChildItem -Path $MLogPath | Where-Object {$_.FullName -like "*$Competition-$Date*" -and $_.FullName -like "*$Content-$Endpoint.json"}
    
                foreach ($File in $($FilesToProcess.FullName)) {

                    Write-CustomWarningMessage -ParentPath $Path -FilePath $File
                    $FileContent = Get-Content $File | ConvertFrom-Json
                    $Processed = $false

                    if ($($FileContent.Competition) -eq $Competition) {

                        $FileCount ++
                        $Processed = $true
                        $PSObject = [PSCustomObject]@{
                            Content = $Content
                            FileCount = $FileCount
                            Processed = $Processed
                        }

                        $ProcessedFiles += $PSObject

                    } # if

                } # foreach

                $ProcessedFiles

            } # if

            if ($Content -ne 'outcomes') {

                $ResultsPath = "$Path\sportsmonk-results\$Competition\$Date"
                $FixtureResults = Import-Csv -Path "$ResultsPath\$Competition-$Date.csv"
                $FilesToProcess = Get-ChildItem -Path $MLogPath | Where-Object {$_.FullName -like "*$Content-$Endpoint.json"}
                $ProcessedFixtures =@()

                foreach ($FixtureResult in $FixtureResults) {

                    foreach ($File in $($FilesToProcess.FullName)) {

                        #Write-CustomWarningMessage -ParentPath $Path -FilePath $File
                        $FileContent = Get-Content $File | ConvertFrom-Json
                        $Processed = $false

                        if ($($FileContent.FixtureId) -eq $($FixtureResult.fixture_id)) {

                            $Processed = $true
                            $PSObject = [PSCustomObject]@{
                                Content = $Content
                                FixtureId = $($FileContent.FixtureId)
                                FixtureName = $($FileContent.FixtureName)
                                Processed = $Processed
                            }

                            $ProcessedFixtures += $PSObject

                        } # if

                    } # foreach

                } # foreach

                Write-Warning "Processing content $Content against endpoint $Endpoint."
                foreach ($FixtureResult in $FixtureResults) {

                    if ($($ProcessedFixtures.FixtureId) -notcontains $($FixtureResult.fixture_id)) {

                        $FixtureResult

                    } # if

                } # foreach

            } # if

        }
        catch {

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

    } # process

} # function