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')]
        [string]$Content,

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

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

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

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

    )
    process{

        $ErrorActionPreference = 'Stop'

        try {

            $ResultsPath = "$Path\sportsmonk-results\$Competition\$Date"
            $FixtureResults = Import-Csv -Path "$ResultsPath\$Competition-$Date.csv"
            [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*"}
            $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

        }
        catch {

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

    } # process

} # function