#!/bin/bash
# Test script for the Vehicle Dashboard

echo "Testing Vehicle Dashboard Setup"
echo "================================"

# Check if the dashboard directory exists
if [ ! -d "/home/Autopartes/dashboard" ]; then
    echo "Error: Dashboard directory not found!"
    exit 1
fi

echo "Dashboard directory found."

# Check if required files exist
files=("index.html" "dashboard.js" "server.py" "requirements.txt")
for file in "${files[@]}"; do
    if [ ! -f "/home/Autopartes/dashboard/$file" ]; then
        echo "Error: $file not found in dashboard directory!"
        exit 1
    fi
done

echo "All required files found."

# Check if the vehicle database exists
if [ ! -f "/home/Autopartes/vehicle_database/vehicle_database.db" ]; then
    echo "Error: Vehicle database not found!"
    exit 1
fi

echo "Vehicle database found."

# Check if Flask is available
if python3 -c "import flask" &> /dev/null; then
    echo "Flask is available."
else
    echo "Flask is not available. Installing..."
    sudo apt-get update
    sudo apt-get install -y python3-flask
fi

# Check if the server is running
if pgrep -f "server.py" > /dev/null; then
    echo "Dashboard server is running on http://localhost:5000"
    echo "You can access the dashboard now!"
else
    echo "Dashboard server is not running."
    echo "To start it, run: cd /home/Autopartes/dashboard && python3 server.py"
fi

echo ""
echo "Dashboard Test Complete!"
echo "Access the dashboard at: http://localhost:5000"