@echo off
rem OnlyCoin icin test edilmis Node.js calisma ortamini secer.
rem Bu dosya CALL ile cagrilmalidir; NODE_EXE degiskenini ust betige aktarir.
set "NODE_EXE="
set "ONLYCOIN_PROJECT_ROOT=%~dp0.."
set "ONLYCOIN_BUNDLED_NODE=%ONLYCOIN_PROJECT_ROOT%\runtime\node-v22.23.1-win-x64\node.exe"

if exist "%ONLYCOIN_BUNDLED_NODE%" (
  set "NODE_EXE=%ONLYCOIN_BUNDLED_NODE%"
  exit /b 0
)

where node >nul 2>nul
if not errorlevel 1 (
  node -e "const [a,b]=process.versions.node.split('.').map(Number);process.exit(a===22&&b>=16?0:1)" >nul 2>nul
  if not errorlevel 1 (
    set "NODE_EXE=node"
    exit /b 0
  )
)

echo.
echo OnlyCoin icin test edilmis Node.js 22.23.1 calisma ortami hazirlaniyor.
echo Bilgisayardaki farkli Node.js surumu yerine proje icindeki sabit surum kullanilacak.
echo.
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%ONLYCOIN_PROJECT_ROOT%\scripts\install-node-runtime.ps1"
if not errorlevel 1 if exist "%ONLYCOIN_BUNDLED_NODE%" (
  set "NODE_EXE=%ONLYCOIN_BUNDLED_NODE%"
  exit /b 0
)

rem Indirme basarisizsa, en az 22.16 olan sistem Node.js son care olarak kullanilir.
where node >nul 2>nul
if not errorlevel 1 (
  node -e "const [a,b]=process.versions.node.split('.').map(Number);process.exit(a>22||(a===22&&b>=16)?0:1)" >nul 2>nul
  if not errorlevel 1 (
    echo UYARI: Sabit calisma ortami indirilemedi; sistem Node.js surumu kullaniliyor.
    set "NODE_EXE=node"
    exit /b 0
  )
)

echo HATA: Uyumlu Node.js calisma ortami bulunamadi.
exit /b 1
