$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 @(
    'Module Overview',
    'File Structure',
    'Smoothing Data Flow',
    'Result Status and Publication Rules',
    'Coordinates and Units',
    'Minimal Call Example',
    'Detailed Usage Guide',
    'Fixture Reports and Visualization',
    'Common Errors',
    'First-Version Limits')) {
    Assert-True $readme.Contains($section) "README must contain section: $section"
}
foreach ($requiredText in @(
    'Local G2',
    'MinimumClearanceReserveMeters',
    'PathSmoothingService',
    'Complete',
    'PartialImprovement',
    'NotNeeded',
    'Unchanged',
    'SimSun',
    'Times New Roman',
    '01-coarse-path-overview',
    '02-all-paths-comparison',
    '03-local-g2-overview',
    '04-curvature-comparison',
    '05-local-g2-diagnostic-candidate')) {
    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.Complete',
    'PathSmoothingStatus.PartialImprovement',
    'PathSmoothingStatus.NotNeeded',
    'PathSmoothingStatus.Unchanged')) {
    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 -notmatch 'ParkrobTrajplanner\\PathSmoothing\\.*\.(svg|png|csv)') 'Batch runner must never write report files below source directories.'

Write-Output 'Path smoothing LocalG2 documentation checks passed.'
