#!/usr/bin/env bash
# bd-groom — launch Claude Code deep grooming for a ticket
#
# Usage:
#   bd-groom <ticket-id>        # deep-groom one ticket
#
# What it does:
#   Invokes /groom slash command which enforces:
#   1. Template compliance check
#   2. SOLID/TDD quick checks
#   3. Implementation simulation — reads actual source, traces dependency chains
#   4. Scope check — flags tickets that need splitting
#   5. Structured grooming report with READY/NEEDS UPDATE/NEEDS SPLIT verdict

set -euo pipefail

TICKET_ID="${1:-}"

if [[ -z "$TICKET_ID" ]]; then
    echo "Usage: bd-groom <ticket-id>"
    echo ""
    echo "Deep-groom a ticket with enforced implementation simulation."
    echo "Produces a structured report with READY / NEEDS UPDATE / NEEDS SPLIT verdict."
    echo ""
    echo "Examples:"
    echo "  bd-groom gpumod-a3f2dd"
    exit 1
fi

# Verify ticket exists
if ! bd show "$TICKET_ID" >/dev/null 2>&1; then
    echo "Error: Could not find ticket $TICKET_ID" >&2
    exit 1
fi

# Check if claude is available
if ! command -v claude >/dev/null 2>&1; then
    echo "Error: claude CLI not found. Install Claude Code first." >&2
    echo "  https://docs.anthropic.com/en/docs/claude-code" >&2
    exit 1
fi

echo "Starting deep grooming for $TICKET_ID..."
exec claude --print "/groom $TICKET_ID"
