param(
    [string]$FixturePath = (Join-Path $PSScriptRoot '..\ParkrobTrajplanner\PathSmoothing\Test\Fixtures\path-smoothing-fixtures.json')
)

$ErrorActionPreference = 'Stop'

$hostProject = Join-Path $PSScriptRoot 'PathSmoothingPngVerificationHost\PathSmoothingPngVerificationHost.csproj'
if (-not (Test-Path -LiteralPath $hostProject)) {
    throw "Path smoothing PNG verification host was not found: $hostProject"
}

$resolvedFixturePath = (Resolve-Path -LiteralPath $FixturePath).Path
& dotnet run --project $hostProject --no-restore -- $resolvedFixturePath
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}

& powershell -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot 'verify_path_smoothing_local_g2_diagnostic_visualization.ps1')
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

$runnerPath = Join-Path $PSScriptRoot 'run_local_g2_diagnostic_visualization.ps1'
$runnerOutput = Join-Path $PSScriptRoot '..\obj\path_smoothing_reports\local-g2-png-smoke'
& powershell -ExecutionPolicy Bypass -File $runnerPath -OutputDirectory $runnerOutput
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$primaryPng = Join-Path $runnerOutput '05-local-g2-diagnostic-candidate.png'
if (-not (Test-Path -LiteralPath $primaryPng)) {
    throw "Local G2 diagnostic runner did not publish $primaryPng"
}

Write-Output 'Path smoothing PNG checks passed.'
