# Verify nexus.ninjakernen.info URLs after website deploy
param(
    [string]$BaseUrl = "https://nexus.ninjakernen.info",
    [string]$OutFile = ""
)

$ErrorActionPreference = "Continue"

$urls = @(
    @{ url = "$BaseUrl/"; note = "Root redirect" }
    @{ url = "$BaseUrl/forside"; note = "Forside" }
    @{ url = "$BaseUrl/om-nexus"; note = "Om Nexus" }
    @{ url = "$BaseUrl/ideen-bag"; note = "Ideen bag" }
    @{ url = "$BaseUrl/support"; note = "Support" }
    @{ url = "$BaseUrl/kontakt"; note = "Kontakt" }
    @{ url = "$BaseUrl/downloads"; note = "Downloads page" }
    @{ url = "$BaseUrl/downloads/latest.json"; note = "Update manifest" }
    @{ url = "$BaseUrl/downloads/releases.json"; note = "Releases catalog" }
    @{ url = "$BaseUrl/downloads/NexusSetup.exe"; note = "Installer" }
    @{ url = "$BaseUrl/downloads/releases/0.1.0-installer3/nexus-shell-poc.zip"; note = "Build 91 ZIP" }
    @{ url = "$BaseUrl/downloads/releases/0.1.0-identity2/nexus-shell-poc.zip"; note = "Build 87 ZIP" }
    @{ url = "$BaseUrl/downloads/releases/0.1.0-identity3/nexus-shell-poc.zip"; note = "Build 88 ZIP" }
    @{ url = "$BaseUrl/health"; note = "Health endpoint" }
    @{ url = "$BaseUrl/robots.txt"; note = "Robots" }
    @{ url = "$BaseUrl/sitemap.xml"; note = "Sitemap" }
)

$results = @()
foreach ($item in $urls) {
    $entry = [ordered]@{ url = $item.url; note = $item.note; status = $null; ok = $false }
    try {
        $r = Invoke-WebRequest -Uri $item.url -Method Head -UseBasicParsing -MaximumRedirection 5 -TimeoutSec 30
        $entry.status = [int]$r.StatusCode
        $entry.ok = ($r.StatusCode -ge 200 -and $r.StatusCode -lt 400)
    } catch {
        $entry.status = $_.Exception.Message
        $entry.ok = $false
    }
    $results += $entry
    $color = if ($entry.ok) { "Green" } else { "Red" }
    Write-Host "$($entry.status)`t$($item.url)" -ForegroundColor $color
}

if (-not $OutFile) {
    $repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
    $OutFile = Join-Path $repoRoot "docs\evidence\nexus-website-v1\verified-links.json"
}
$dir = Split-Path $OutFile -Parent
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
($results | ConvertTo-Json -Depth 4) | Set-Content $OutFile -Encoding UTF8
Write-Host "Wrote $OutFile" -ForegroundColor Cyan
return $results
