#!/bin/bash
# Vera Medical CRM - Automated Setup Script

echo "============================================================"
echo "VERA MEDICAL CRM - AUTOMATED SETUP"
echo "============================================================"
echo ""

# Check if Python 3 is installed
if ! command -v python3 &> /dev/null; then
    echo "❌ Error: Python 3 is not installed"
    echo "Please install Python 3.8 or higher and try again"
    exit 1
fi

echo "✓ Python 3 found: $(python3 --version)"
echo ""

# Check if VMdata.csv exists
if [ ! -f "VMdata.csv" ]; then
    echo "❌ Error: VMdata.csv not found"
    echo "Please ensure VMdata.csv is in the current directory"
    exit 1
fi

echo "✓ VMdata.csv found"
echo ""

# Install dependencies
echo "Step 1: Installing Python dependencies..."
echo "------------------------------------------------------------"
pip install -r requirements.txt

if [ $? -ne 0 ]; then
    echo "❌ Error: Failed to install dependencies"
    exit 1
fi

echo ""
echo "✓ Dependencies installed successfully"
echo ""

# Import data
echo "Step 2: Importing data from CSV..."
echo "------------------------------------------------------------"
echo "This may take several minutes for 305,679 records..."
echo ""

python3 import_data.py

if [ $? -ne 0 ]; then
    echo "❌ Error: Data import failed"
    exit 1
fi

echo ""
echo "✓ Data import completed successfully"
echo ""

# Check if database was created
if [ ! -f "vera_medical.db" ]; then
    echo "❌ Error: Database file was not created"
    exit 1
fi

echo "✓ Database file created: vera_medical.db"
echo ""

# Setup complete
echo "============================================================"
echo "SETUP COMPLETE! 🎉"
echo "============================================================"
echo ""
echo "Your Vera Medical CRM is ready to use!"
echo ""
echo "To start the application, run:"
echo "  python3 app.py"
echo ""
echo "Then open your browser to:"
echo "  http://localhost:5050"
echo ""
echo "============================================================"

