@echo off
echo =========================================
echo  🧪 Running backend tests...
echo =========================================

if exist ".venv\Scripts\pytest.exe" (
    set PYTEST_BIN=".venv\Scripts\pytest"
) else (
    set PYTEST_BIN="pytest"
)

%PYTEST_BIN% tests\ -v
if %errorlevel% neq 0 (
    echo.
    echo ❌ Tests failed! Aborting server start! Please fix the errors.
    exit /b %errorlevel%
)

echo.
echo ✅ Tests passed successfully! Starting dev server...
echo.

if exist ".venv\Scripts\uvicorn.exe" (
    .venv\Scripts\uvicorn main:app --host 127.0.0.1 --port 8000 --reload
) else (
    uvicorn main:app --host 127.0.0.1 --port 8000 --reload
)
