#!/bin/bash
echo "============================================"
echo "  KADIYAM BILLING SYSTEM - SETUP"
echo "============================================"
echo ""

# Check Node.js
if ! command -v node &> /dev/null; then
    echo "ERROR: Node.js not found. Install from https://nodejs.org"
    exit 1
fi
echo "✅ Node.js $(node --version)"

# Check MongoDB
if ! command -v mongod &> /dev/null; then
    echo "⚠️  MongoDB not found in PATH. Make sure MongoDB is running."
else
    echo "✅ MongoDB found"
fi

# Install dependencies
echo ""
echo "Installing npm dependencies..."
npm install
if [ $? -ne 0 ]; then
    echo "ERROR: npm install failed"
    exit 1
fi
echo "✅ Dependencies installed"

echo ""
echo "============================================"
echo "  Starting Kadiyam Billing System..."
echo "  URL: http://localhost:3000"
echo "  Setup (first time): http://localhost:3000/setup"
echo "  Login: admin@kadiyam.com / Admin@123"
echo "============================================"
echo ""
node server.js
