# Reset local Identity database and restart Nexus (fixes "forkert password" on corrupted/empty DB).
param(
  [string]$InstallRoot = "C:\NinjaNexusPOC"
)

$ErrorActionPreference = "Stop"
if ($PSScriptRoot -and (Test-Path (Join-Path $PSScriptRoot "identity"))) {
  $InstallRoot = $PSScriptRoot
}

Write-Host "=== RESET NEXUS LOGIN ===" -ForegroundColor Cyan
Write-Host "Root: $InstallRoot"

foreach ($name in @("NexusShell", "NexusIdentity.Api")) {
  Get-Process -Name $name -ErrorAction SilentlyContinue | Stop-Process -Force
}

$db = Join-Path $InstallRoot "identity\nexus-identity.db"
Get-ChildItem -LiteralPath (Join-Path $InstallRoot "identity") -Filter "nexus-identity.db*" -ErrorAction SilentlyContinue |
  Remove-Item -Force

Write-Host "Database slettet. Starter Nexus..." -ForegroundColor Yellow
& (Join-Path $PSScriptRoot "START-NEXUS-SAFE-MODE.ps1") -InstallRoot $InstallRoot
