@echo off
REM run-backend.bat - Windows startup script for Channel Backend.
echo [INFO] Verifying Docker installation...
where docker >nul 2>nul
if %errorlevel% neq 0 (
    echo [ERROR] Docker is not installed or not in PATH. Please install Docker.
    exit /b 1
)

echo [INFO] Starting PostgreSQL container...
docker compose up -d postgres || docker-compose up -d postgres

echo [INFO] Checking if database configuration exists...
if not exist Channel-Backend\.env (
    echo [INFO] Generating Channel-Backend\.env config...
    (
        echo PORT=5000
        echo DATABASE_URL="postgresql://pipeline_admin:secure_pipeline_2024@localhost:5433/backend_channel?schema=public"
        echo JWT_SECRET="super-secret-jwt-key-2026-world-class"
        echo NODE_ENV="development"
    ) > Channel-Backend\.env
)

echo [INFO] Installing backend dependencies...
cd Channel-Backend
call npm install

echo [INFO] Generating Prisma client...
call npx prisma generate

echo [INFO] Aligning database schema with Prisma...
call npx prisma db push

echo [INFO] Seeding database...
call npx ts-node seed.ts

echo [INFO] Starting Express backend dev server...
call npm run dev
