@echo off
setlocal
title Turis Tv
cd /d "%~dp0"

echo ========================================
echo              TURIS TV
echo ========================================
echo.

where node >nul 2>nul
if errorlevel 1 (
  echo Node.js bulunamadi.
  echo Lutfen once Node.js 20 veya daha yeni bir surumu yukleyin:
  echo https://nodejs.org/
  echo.
  pause
  exit /b 1
)

if not exist ".env" (
  echo Ilk ayarlar hazirlaniyor...
  > ".env" echo DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/app_db
  >> ".env" echo LINK_PIN_HASH=55806a655d0627b195c9482dfaccf14773c572d05a9854605e20095d70723bd0
  for /f %%i in ('powershell -NoProfile -Command "[guid]::NewGuid().ToString('N')+[guid]::NewGuid().ToString('N')"') do >> ".env" echo SESSION_SECRET=%%i
)

if not exist "node_modules" (
  echo Paketler yukleniyor. Bu islem ilk seferde birkac dakika surebilir...
  call npm install
  if errorlevel 1 (
    echo Paket yukleme basarisiz oldu.
    pause
    exit /b 1
  )
)

echo.
echo Turis Tv baslatiliyor: http://localhost:3000
echo Bu pencereyi acik birakin. Kapatmak icin Ctrl+C tuslarina basin.
echo.

start "" powershell -WindowStyle Hidden -NoProfile -Command "Start-Sleep -Seconds 6; Start-Process 'http://localhost:3000'"
call npm run dev

pause
