#!/bin/bash

# Exit on error
set -e

VENV_DIR="venv"

echo "Checking for virtual environment..."
if [ ! -d "$VENV_DIR" ]; then
    echo "Creating virtual environment..."
    python3 -m venv "$VENV_DIR"
fi

echo "Activating virtual environment..."
source "$VENV_DIR/bin/activate"

if [ "$1" == "--clean" ]; then
    echo "Performing clean start..."
    echo "Removing database..."
    rm -f database.db instance/database.db
    echo "Clearing uploads..."
    rm -rf static/uploads/*
fi

echo "Upgrading pip and setuptools..."
pip install --upgrade pip setuptools wheel

echo "Installing/Updating requirements..."
pip install -r requirements.txt

echo "Starting Character Browser..."
python3 app.py
