# Capture NexusSetup evidence screenshots into docs/evidence/nexus-installer-v2/
param(
  [string]$OutputDir = ""
)

$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
$installerProject = Join-Path $repoRoot "source\nexus-installer\NexusInstaller.csproj"
$evidenceDir = if ($OutputDir) { $OutputDir } else { Join-Path $repoRoot "docs\evidence\nexus-installer-v2" }

Write-Host "=== Nexus Installer Screenshot Capture ===" -ForegroundColor Cyan
Write-Host "Output: $evidenceDir"

dotnet build $installerProject -c Release
if ($LASTEXITCODE -ne 0) { throw "Build failed." }

New-Item -ItemType Directory -Path $evidenceDir -Force | Out-Null

$exe = Join-Path $repoRoot "source\nexus-installer\bin\Release\net8.0-windows\NexusSetup.exe"
if (-not (Test-Path $exe)) {
  throw "NexusSetup.exe not found at $exe"
}

Write-Host "Capturing screenshots (window will flash briefly)..." -ForegroundColor Yellow
& $exe --capture-screenshots $evidenceDir | Out-Null

$expected = @(
  "installer-welcome.png",
  "installer-requirements.png",
  "installer-identity.png",
  "installer-installing.png",
  "installer-complete.png"
)

foreach ($name in $expected) {
  $path = Join-Path $evidenceDir $name
  if (-not (Test-Path $path)) {
    throw "Missing screenshot: $path"
  }
  $size = (Get-Item $path).Length
  Write-Host "  OK  $name ($size bytes)" -ForegroundColor Green
}

Write-Host ""
Write-Host "Done. Screenshots saved to $evidenceDir" -ForegroundColor Green
