#!/bin/bash

# Email Monitoring Script for Signup Events
# This script monitors the backend logs for email-related events

echo "🔍 Monitoring Signup Email Events..."
echo "📝 Watching Backend logs for email activity"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

cd "$(dirname "$0")"

# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo "Filtering for signup and email-related events..."
echo ""

# Start the backend and monitor for email events
npm start 2>&1 | grep -E "(User registered|Welcome email|email sent|email error|✅|❌|📧)" --line-buffered | while read line; do
    if [[ $line == *"✅"* ]] || [[ $line == *"Welcome email sent"* ]]; then
        echo -e "${GREEN}$line${NC}"
    elif [[ $line == *"❌"* ]] || [[ $line == *"error"* ]] || [[ $line == *"Error"* ]]; then
        echo -e "${RED}$line${NC}"
    elif [[ $line == *"📧"* ]]; then
        echo -e "${YELLOW}$line${NC}"
    else
        echo "$line"
    fi
done
