#!/usr/bin/env bash
# Project-level ticket wrapper that delegates to aitrackdown

set -e

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

# Check if virtual environment exists and activate it
VENV_DIR="$SCRIPT_DIR/venv"
if [ -d "$VENV_DIR" ]; then
    source "$VENV_DIR/bin/activate"
elif [ -f "$SCRIPT_DIR/scripts/ticket" ]; then
    # Delegate to the scripts version if no venv
    exec "$SCRIPT_DIR/scripts/ticket" "$@"
fi

# Check if aitrackdown is available
if ! command -v aitrackdown &> /dev/null; then
    echo "Error: aitrackdown not found. Please run ./install_dev.sh"
    exit 1
fi

# Execute the ticket script logic
exec "$SCRIPT_DIR/scripts/ticket" "$@"