@echo off
setlocal
cd /d "%~dp0"

echo ==== 1. Stop old GenServer (if any), then start new ====
taskkill /F /IM GenServer.exe >nul 2>nul
timeout /t 1 /nobreak >nul
start "GenServer" /min "%~dp0..\bin\GenServer.exe" "%~dp0genserver-config.json"
timeout /t 2 /nobreak >nul

echo ==== 2. Health check ====
powershell -NoProfile -Command "try { (Invoke-RestMethod -Uri 'http://localhost:8899/health' -TimeoutSec 5) | ConvertTo-Json } catch { Write-Host 'health FAIL: ' $_.Exception.Message }"

echo ==== 3. Trigger non-standard gen (KC0032-87) ====
powershell -NoProfile -Command "try { (Invoke-RestMethod -Method Post -Uri 'http://localhost:8899/gen' -Body '{\"series\":\"KC\",\"params\":{\"type\":\"00\",\"bore\":32,\"stroke\":87,\"magnet\":\"\",\"mount\":\"\"},\"code\":\"KC0032-87\"}' -ContentType 'application/json' -TimeoutSec 5) | ConvertTo-Json } catch { Write-Host 'gen FAIL: ' $_.Exception.Message }"

echo ==== 4. Latest job file (newest first) ====
dir /b /o-d "jobs\job_*.json" 2>nul

echo ==== 5. worker-config.txt (check nxBin line present) ====
type "worker-config.txt"

echo ==== 6. Output dir (generated models land here) ====
dir /b /s "output" 2>nul

echo ==== done ====
endlocal
