# PowerShell script to replace clientId with authToken in method calls
# Usage: .\replace_clientid_calls.ps1 <file_path>

param(
    [Parameter(Mandatory=$true)]
    [string]$FilePath
)

if (-not (Test-Path $FilePath)) {
    Write-Error "File not found: $FilePath"
    exit 1
}

Write-Host "Replacing clientId with authToken in method calls: $FilePath"

# Read file content
$Content = Get-Content $FilePath -Raw

# Replace patterns where clientId is used as parameter to other methods
$Replacements = @(
    @{
        Pattern = '_i\.ValidateStepOrder\(clientId, '
        Replacement = '_i.ValidateStepOrder(authToken, '
    },
    @{
        Pattern = '_i\.ValidateStep\(clientId, '
        Replacement = '_i.ValidateStep(authToken, '
    },
    @{
        Pattern = '_i\.CanDeleteStep\(clientId, '
        Replacement = '_i.CanDeleteStep(authToken, '
    }
)

foreach ($Replacement in $Replacements) {
    $Content = $Content -replace $Replacement.Pattern, $Replacement.Replacement
    Write-Host "Replaced: $($Replacement.Pattern)"
}

# Write updated content
Set-Content $FilePath $Content -NoNewline

Write-Host "ClientId method calls replaced with authToken."
