#!/bin/bash

# D&D 4e VTT Server Startup Script
# This script starts both the backend server and frontend client in development mode

echo "🎲 Starting D&D 4e Virtual Tabletop servers..."
echo "📍 Working directory: $(pwd)"
echo ""

# Check if we're in the correct directory
if [ ! -f "package.json" ]; then
    echo "❌ Error: package.json not found. Make sure you're in the project root directory."
    exit 1
fi

# Check if node_modules exists
if [ ! -d "node_modules" ]; then
    echo "📦 Installing dependencies..."
    npm install
fi

# Check if client node_modules exists
if [ ! -d "client/node_modules" ]; then
    echo "📦 Installing client dependencies..."
    cd client && npm install && cd ..
fi

echo "🚀 Starting servers..."
echo "   - Backend server will run on http://localhost:3003"
echo "   - Frontend client will run on http://localhost:5173"
echo ""
echo "Press Ctrl+C to stop both servers"
echo "----------------------------------------"

# Start both servers using the npm dev script
npm run dev