@echo off
setlocal
echo ============================================
echo   NotifyPulse Agent V4 - Build
echo ============================================
echo.

where python >nul 2>&1
if errorlevel 1 (
    echo ERROR: Python not found in PATH
    pause & exit /b 1
)

set "PY=python"
where py >nul 2>&1
if not errorlevel 1 set "PY=py -3"

echo [1/2] Installing dependencies...
%PY% -m pip install -r requirements.txt --quiet
if errorlevel 1 ( echo FAILED & pause & exit /b 1 )

echo [2/2] Building executable...
set "ICON_ARG="
if exist "icon.ico" set "ICON_ARG=--icon icon.ico"

%PY% -m PyInstaller --noconfirm --onefile --windowed ^
  --name "NotifyPulseAgent-V4" ^
  %ICON_ARG% ^
  --hidden-import=websockets ^
  --hidden-import=requests ^
  --hidden-import=winotify ^
  --hidden-import=pystray ^
  --hidden-import=PIL ^
  --add-data "agent_config.example.json;." ^
  client.py

if errorlevel 1 (
    echo BUILD FAILED
    pause & exit /b 1
)

echo.
echo ============================================
echo   SUCCESS: dist\NotifyPulseAgent-V4.exe
echo ============================================
pause
