# Stop Nexus Shell and Identity POC processes.
param(
  [string]$InstallRoot = $PSScriptRoot
)

$ErrorActionPreference = "SilentlyContinue"
$logsDir = Join-Path $InstallRoot "logs"
$pidFile = Join-Path $logsDir "nexus-poc.pids.json"

Write-Host "Stopping Nexus POC processes..." -ForegroundColor Cyan

if (Test-Path $pidFile) {
  try {
    $info = Get-Content $pidFile -Raw | ConvertFrom-Json
    foreach ($name in @("shellPid", "identityPid")) {
      $pidVal = [int]$info.$name
      if ($pidVal -gt 0) {
        Stop-Process -Id $pidVal -Force -ErrorAction SilentlyContinue
        Write-Host "  Stopped PID $pidVal"
      }
    }
  } catch {}
  Remove-Item -LiteralPath $pidFile -Force
}

Get-Process -Name "NexusShell" -ErrorAction SilentlyContinue | Stop-Process -Force
Get-Process -Name "NexusIdentity.Api" -ErrorAction SilentlyContinue | Stop-Process -Force

Write-Host "Done. Windows is unchanged." -ForegroundColor Green
