#!/bin/bash
# Setup script for django-rsgi example project

set -e  # Exit on any error

echo "Setting up django-rsgi example project..."
echo ""

# Change to project directory
cd "$(dirname "$0")/.."

if [ -f db.sqlite3 ]; then
    echo "Removing existing database..."
    rm -i db.sqlite3 || exit 1
fi

echo "Installing dependencies..."
uv pip install -e .

echo "Running database migrations..."
uv run python manage.py migrate

echo "Loading sample videos..."
uv run python manage.py loaddata initial_videos.json

echo "Creating superuser..."
echo "Creating admin user with credentials: admin/admin123"
echo "from django.contrib.auth.models import User; User.objects.filter(username='admin').delete(); User.objects.create_superuser('admin', 'admin@example.com', 'admin123')" | uv run python manage.py shell

echo ""
echo "Setup complete!"
echo ""
echo "Next steps:"
echo "  1. Start the server: uv run ./manage.py serve"
echo "  2. Visit: http://localhost:8000/"
echo "  3. Admin access: http://localhost:8000/admin/"
echo "     - Username: admin"
echo "     - Password: admin123"
echo ""
echo "The demo includes:"
echo "  - Video file serving with range request support"
echo "  - Real-time server time via Server-Sent Events"
echo "  - Static and media file optimizations"
