$ErrorActionPreference = 'Stop'

$root = Join-Path $PSScriptRoot '..'
$readmePath = Join-Path $root 'ParkrobTrajplanner\PathSmoothing\README.md'
$demoPath = Join-Path $root 'ParkrobTrajplanner\PathSmoothing\Test\PathSmoothingComparisonDemo.cs'
$runnerPath = Join-Path $PSScriptRoot 'run_path_smoothing_comparison.ps1'

function Assert-True($actual, [string]$message) {
    if (-not $actual) { throw $message }
}

Assert-True (Test-Path -LiteralPath $readmePath) 'Path smoothing README is missing.'
Assert-True (Test-Path -LiteralPath $demoPath) 'Path smoothing comparison demo is missing.'
Assert-True (Test-Path -LiteralPath $runnerPath) 'Path smoothing comparison batch runner is missing.'

$readme = Get-Content -Raw -Encoding UTF8 $readmePath
foreach ($section in @(
    '## Units and coordinates',
    '## Facade usage',
    '## Status handling and fallback',
    '## Fixture freshness',
    '## IEEE colors, fonts, and Windows PNG',
    '## SQP boundary',
    '## Output files')) {
    Assert-True $readme.Contains($section) "README must contain section: $section"
}
foreach ($requiredText in @(
    'meters',
    'radians',
    'PathSmoothingService',
    'FallbackToCoarsePath',
    'SimSun',
    'Times New Roman',
    '600 dpi',
    'discrete samples',
    '01-coarse-path-overview',
    '02-all-paths-comparison',
    '03-cubic-bspline-overview',
    '04-local-cubic-bezier-overview',
    '05-piecewise-quintic-overview',
    '06-curvature-comparison',
    'PDF/EPS')) {
    Assert-True $readme.Contains($requiredText) "README must document: $requiredText"
}

$demo = Get-Content -Raw -Encoding UTF8 $demoPath
foreach ($requiredText in @(
    'PathSmoothingComparisonDemo',
    'PathSmoothingService',
    'PathSmoothingComparisonService',
    'SmoothingReportExporter',
    'SmoothingScenarioFactory',
    'PathSmoothingStatus.Success',
    'PathSmoothingStatus.FallbackToCoarsePath')) {
    Assert-True $demo.Contains($requiredText) "Demo must use: $requiredText"
}

$runner = Get-Content -Raw -Encoding UTF8 $runnerPath
Assert-True ($runner -match '\[switch\]\$FixtureOnly') 'Batch runner must offer -FixtureOnly.'
Assert-True $runner.Contains('obj\path_smoothing_reports') 'Batch runner must write reports below ClumsyPilot/obj/path_smoothing_reports.'
Assert-True $runner.Contains('--export-fixtures') 'Batch runner must export all eight fast fixtures by default.'
Assert-True $runner.Contains('if (-not $FixtureOnly)') 'Batch runner must make end-to-end cases optional.'
Assert-True ($runner -notmatch 'ParkrobTrajplanner\\PathSmoothing\\.*\.(svg|png|csv)') 'Batch runner must never write report files below source directories.'

Write-Output 'Path smoothing documentation checks passed.'
