$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $PSScriptRoot
Set-Location $root

python scripts\local_stack.py stop @args
if ($LASTEXITCODE -ne 0) {
  exit $LASTEXITCODE
}

$dataDir = Join-Path $root ".data_local"
if (Test-Path $dataDir) {
  Remove-Item -Path $dataDir -Recurse -Force
}

$summaryPath = Join-Path $root ".local_stack\demo-seed-summary.json"
if (Test-Path $summaryPath) {
  Remove-Item -Path $summaryPath -Force
}

python scripts\local_stack.py start @args
if ($LASTEXITCODE -ne 0) {
  exit $LASTEXITCODE
}

& "$PSScriptRoot\smoke_test.ps1"
if ($LASTEXITCODE -ne 0) {
  exit $LASTEXITCODE
}

python scripts\demo_seed.py
if ($LASTEXITCODE -ne 0) {
  exit $LASTEXITCODE
}

Write-Host ""
Write-Host "Demo environment is ready."
Write-Host "UI: http://localhost:8080/operator"
Write-Host "Login: admin / admin123"
Write-Host "KB keyword: demo-showcase"
Write-Host "Summary: .local_stack\demo-seed-summary.json"
Write-Host "Stop: powershell -ExecutionPolicy Bypass -File scripts\stop_all_local.ps1"
