public/Invoke-AutomatedClaudeAPIRequest.ps1

function Invoke-AutomatedClaudeAPIRequest {

    [CmdletBinding()]
    param(

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

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

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

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

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


    )
    process{

        $ErrorActionPreference = 'Stop'

        try {
    
            $FPath = "$Path\fixture-artifact\multi-media\$Competition\$Date"
            $IPath = "$Path\git-hub\sportsmonk-api\Claude-ai\instructions\preview_instructions_pt3_orange.txt"
            $Templates = Get-ChildItem -Path $FPath -File -Recurse -ErrorAction Stop | Where-Object {$_.Name -like '*twitter-review.txt' -and $_.Name -notlike '*updated-twitter*'}

            foreach ($Template in $Templates) {

                Write-Warning -Message "Processing: $($Template.Name)."
                $FileName = $($Template.Name)
                $ExportPath = $($Template.FullName).Split("\$FileName")[0]
                $NewFileName = $($Template.Name).Replace('twitter-review','updated-twitter-review')
                $ExportFile = "$ExportPath\$NewFileName"
                $ExportFileExists = Test-Path -Path $ExportFile

                if (!$ExportFileExists) {

                    Write-CustomWarningMessage -ParentPath $Path -FilePath $($Template.FullName)
                    
                    $TPath = $($Template.FullName)
                    $Response = Invoke-ClaudeAPIRequest -Token $Token -FilePath $TPath -InstructionFilePath $IPath
                    $ResponseText = $($Response.content.text)

                    if ($ResponseText -like '*Remains the same*') {

                        Write-Warning -Message "No Formatting: $($Template.Name)."
                        $ResponseText

                    }
                    else {

                        Set-Content -Path $ExportFile -Value $ResponseText

                    } # if

                }
                else {

                    Write-Warning -Message "Already exists: $NewFileName."

                } # if

                if ($Show) {

                    $ResponseText
                    #$Response.content.text

                } # if

            } # foreach
        }
        catch {

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

        } # try catch

    } # process

} # function