
#!/usr/bin/env bash

set -e

if ! command -v uv &> /dev/null; then
    echo "Error: uv is not installed."
    echo "Install it from https://docs.astral.sh/uv/getting-started/installation/"
    exit 1
fi

echo "Using Python version from .python-version"
uv python install

echo "Syncing dependencies from pyproject.toml / uv.lock..."
uv sync

if [ ! -f .env ]; then
    echo "Creating .env file..."
    cat <<EOF > .env
LLM_PROVIDER=groq
EMBEDDING_PROVIDER="sentence_transformers"
GROQ_API_KEY=
BACKEND_URL="https://api.bhasika.com/testnp/"
PG_HOST=
PG_PORT=
PG_USER=
PG_PASSWORD=
PG_DATABASE=
EOF
    echo ".env created."
else
    echo ".env file already exists, skipping creation."
fi

echo "------------------------------------------------"
echo "Create the database and add following credentials to .env"
echo "GROQ_API_KEY"
echo "PG_HOST"
echo "PG_PORT"
echo "PG_USER"
echo "PG_PASSWORD"
echo "PG_DATABASE"
echo "------------------------------------------------"


echo "------------------------------------------------"
echo "Sync data with (just run sync_excel_files for testing)"
echo "  uv run -m scripts.sync_blogs"
echo "  uv run -m scripts.sync_programs"
echo "To start the UI, run:"
echo "  uv run streamlit run ui.py --server.port 8000"
echo "To start the uvicorn server, run:"
echo "  uv run uvicorn app.main:app --reload"
echo "------------------------------------------------"
