@echo off
chcp 65001 >nul
title Stocknews - Supabase aktarma koprusu (port acmaz)
cd /d "%~dp0"
where node >nul 2>nul
if errorlevel 1 (
  echo Node.js 18 veya ustunu kurun: https://nodejs.org
  pause
  exit /b 1
)
if not defined STOCKNEWS_BRIDGE_PORT set STOCKNEWS_BRIDGE_PORT=8766
curl --fail --silent --max-time 2 http://127.0.0.1:%STOCKNEWS_BRIDGE_PORT%/version >nul 2>nul
if not errorlevel 1 (
  echo Bu portta zaten bir Stocknews koprusu calisiyor. Once o pencereyi kapatin;
  echo bu pencere yerel kopru gorevini de ustlenir.
  pause
  exit /b 1
)
set PAIRARG=
if not exist "%LOCALAPPDATA%\Stocknews\bridge\stocknews-bridge-relay.json" (
  echo.
  echo Bu kopru henuz eslestirilmemis.
  echo Stocknews'te admin hesabiyla: Admin Paneli ^> Kopruler ^> "Kopru ekle" ile 15 dakika gecerli kodu alin.
  set /p PAIRCODE=Eslestirme kodu ^(ornek ABCD-EFGH-JKMN-PQRS^): 
)
if defined PAIRCODE set PAIRARG=--pair %PAIRCODE%
echo.
echo ================================================================
echo  Supabase aktarma: kopru internete PORT ACMAZ; Supabase'e yalniz disa dogru baglanir.
echo  Telefonda Tailscale gerekmez; Stocknews'e giris yapmaniz yeterli.
echo  Bu pencere acik kaldigi surece calisir. Kapatmak icin pencereyi kapatin.
echo  Tailscale ile ayni pencerede: stocknews-bridge-remote.bat --relay
echo ================================================================
echo.
node "%~dp0stocknews-bridge.js" --relay %PAIRARG% %*
echo.
echo Kopru kapandi.
pause
