#!/bin/bash
# MLL Intake Assistant - Startup Script

set -e

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

echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}  MLL Intake Assistant - Starting...   ${NC}"
echo -e "${GREEN}========================================${NC}"

# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

# Check for .env file
if [ ! -f ".env" ]; then
    echo -e "${YELLOW}Warning: .env file not found${NC}"
    if [ -f ".env.example" ]; then
        echo -e "${YELLOW}Creating .env from .env.example${NC}"
        cp .env.example .env
        echo -e "${RED}Please update .env with your ANTHROPIC_API_KEY${NC}"
    fi
fi

# Create logs directory
mkdir -p logs

# Check Python version
python3 --version

# Check for required packages
echo -e "\n${YELLOW}Checking dependencies...${NC}"
python3 -c "import streamlit; print('✓ streamlit')" 2>/dev/null || echo "✗ streamlit - install with: pip install streamlit"
python3 -c "import anthropic; print('✓ anthropic')" 2>/dev/null || echo "✗ anthropic - install with: pip install anthropic"
python3 -c "import pandas; print('✓ pandas')" 2>/dev/null || echo "✗ pandas - install with: pip install pandas"
python3 -c "import pydantic; print('✓ pydantic')" 2>/dev/null || echo "✗ pydantic - install with: pip install pydantic"

# Start Streamlit
echo -e "\n${GREEN}Starting MLL Intake Assistant...${NC}"
echo -e "${YELLOW}The application will open in your browser.${NC}"
echo -e "${YELLOW}Or access it at: http://localhost:8501${NC}\n"

streamlit run app.py \
    --server.port=8501 \
    --server.address=0.0.0.0 \
    --server.headless=true \
    --browser.gatherUsageStats=false \
    --theme.primaryColor="#1976d2" \
    --theme.backgroundColor="#ffffff" \
    --theme.secondaryBackgroundColor="#f5f5f5" \
    --theme.textColor="#333333"
