@echo off
setlocal
title Mengya Profile - Start Backend
echo [INFO] Starting backend API service...
cd /d "%~dp0mengyaprofile-backend"

REM Choose Python launcher: prefer py, else python
set "PY=python"
where py >nul 2>nul
if not errorlevel 1 set "PY=py"

where %PY% >nul 2>nul
if errorlevel 1 goto no_python

echo [INFO] Installing Python dependencies...
%PY% -m pip install -r requirements.txt
if errorlevel 1 goto pip_fail

echo [INFO] Starting in DEVELOPMENT mode...
echo [INFO] Frontend should run on http://localhost:3000
echo [INFO] Backend API on http://localhost:5000
set RUN_MODE=development

echo [INFO] Running: %PY% app.py
%PY% app.py
if errorlevel 1 goto run_fail
goto end

:no_python
echo [ERROR] Python not found. Install Python 3 and ensure PATH.
goto end

:pip_fail
echo [ERROR] pip install failed.
goto end

:run_fail
echo [ERROR] Backend failed to start.
goto end

:end
endlocal
