@echo off
echo Starting Fengye Website Backend in Development Mode...

REM 检查Python环境
python --version >nul 2>&1
if %errorlevel% neq 0 (
    echo Python is not installed or not in PATH.
    pause
    exit /b 1
)

REM 检查Redis是否运行
redis-cli ping >nul 2>&1
if %errorlevel% neq 0 (
    echo Redis is not running. Please start Redis server first.
    pause
    exit /b 1
)

REM 检查环境变量文件
if not exist .env (
    echo .env file not found. Please create one based on .env.example
    pause
    exit /b 1
)

REM 激活虚拟环境（如果使用conda）
call conda activate fengye

REM 安装依赖
echo Installing dependencies...
pip install -r requirements.txt

REM 运行数据库迁移
echo Running database migrations...
python manage.py migrate

REM 启动ASGI服务器
echo Starting ASGI server...
daphne -b 0.0.0.0 -p 8000 fengye_website_backend.asgi:application

REM 如果服务器意外停止，保持窗口打开
echo.
echo Server stopped. Press any key to exit...
pause >nul 