#!/bin/bash

# Trainings24x7 Platform - Start Script
# ==============================

echo "Starting Trainings24x7 Platform Services..."

# Check if MongoDB is running
if ! pgrep mongod > /dev/null; then
    echo "📦 Starting MongoDB..."
    sudo mkdir -p /data/db
    sudo chmod 777 /data/db
    mongod --dbpath /data/db --bind_ip_all > /var/log/mongodb.log 2>&1 &
    sleep 3
fi

# Start all services via supervisor
echo "🔧 Starting backend and frontend services..."
sudo supervisorctl start all

# Wait a moment for services to start
sleep 5

# Check status
echo "📊 Service Status:"
sudo supervisorctl status | grep -E "(backend|frontend)"

echo ""
echo "✅ Trainings24x7 Platform Started!"
echo "📱 Frontend: http://localhost:3000"
echo "🔧 Backend: http://localhost:8001/api/"
echo ""
echo "📧 Demo Login: demo@trainings24x7.com"
echo "🔑 Demo Password: demo123"