#!/usr/bin/env bash
# Ticket Management Shell Wrapper for claude-mpm
#
# WHY: This shell script provides backward compatibility for users who use the
# 'ticket' command directly from the shell. It delegates all operations to the
# integrated claude-mpm tickets command.
#
# DESIGN DECISION: This thin wrapper maintains the existing shell interface while
# delegating to the new claude-mpm tickets subcommands for consistency.

# Find the project root
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$( cd "$SCRIPT_DIR/.." && pwd )"

# Check if we should use local claude-mpm or installed version
if [ -f "$PROJECT_ROOT/claude-mpm" ] && [ -d "$PROJECT_ROOT/src/claude_mpm" ]; then
    # Use local development version
    CLAUDE_MPM="$PROJECT_ROOT/claude-mpm"
else
    # Use installed version
    CLAUDE_MPM="claude-mpm"
fi

# Check if claude-mpm is available
if ! command -v "$CLAUDE_MPM" &> /dev/null && [ "$CLAUDE_MPM" = "claude-mpm" ]; then
    echo "Error: claude-mpm not found. Please ensure it's installed and in your PATH."
    echo "Install with: pip install claude-mpm"
    exit 1
fi

# Delegate to claude-mpm tickets command
# If no arguments or help requested, show help
if [ $# -eq 0 ] || [ "$1" = "help" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
    exec "$CLAUDE_MPM" tickets --help
else
    # Pass all arguments to claude-mpm tickets
    exec "$CLAUDE_MPM" tickets "$@"
fi