#!/bin/bash
# Progress Tracker for Trax Development
# Shows comprehensive development status

echo "═══════════════════════════════════════════════════════"
echo "           TRAX DEVELOPMENT PROGRESS TRACKER           "
echo "═══════════════════════════════════════════════════════"
echo ""

# 1. Task Master Status
echo "📋 TASK MASTER STATUS"
echo "────────────────────"
if command -v task-master &> /dev/null; then
    echo "In Progress:"
    task-master list --status=in-progress 2>/dev/null | head -3
    echo ""
    echo "Next Tasks:"
    task-master list --status=pending 2>/dev/null | head -3
else
    echo "Task Master not configured"
fi
echo ""

# 2. Test Coverage
echo "🧪 TEST COVERAGE"
echo "────────────────"
if [ -d "tests" ]; then
    echo "Running coverage analysis..."
    uv run pytest --cov=src --cov-report=term-missing --quiet 2>/dev/null | tail -5
else
    echo "No tests directory found"
fi
echo ""

# 3. Code Quality - File Sizes
echo "📏 FILE SIZE CHECK"
echo "────────────────"
echo "Files over 300 lines:"
find src -name "*.py" -exec wc -l {} + 2>/dev/null | awk '$1 > 300 {print $2 ": " $1 " lines (⚠️ over limit)"}' | head -5
LARGE_FILES=$(find src -name "*.py" -exec wc -l {} + 2>/dev/null | awk '$1 > 300' | wc -l)
TOTAL_FILES=$(find src -name "*.py" 2>/dev/null | wc -l)
echo "Summary: $LARGE_FILES/$TOTAL_FILES files exceed 300 lines"
echo ""

# 4. Type Checking
echo "🔍 TYPE CHECKING"
echo "────────────────"
if command -v mypy &> /dev/null; then
    ERROR_COUNT=$(uv run mypy src/ 2>/dev/null | grep -c "error:" || echo "0")
    echo "Type errors found: $ERROR_COUNT"
else
    echo "MyPy not configured"
fi
echo ""

# 5. Linting Status
echo "🎨 CODE FORMATTING"
echo "────────────────"
if command -v ruff &> /dev/null; then
    RUFF_ERRORS=$(uv run ruff check src/ 2>&1 | grep -c "error" || echo "0")
    echo "Ruff errors: $RUFF_ERRORS"
fi
if command -v black &> /dev/null; then
    BLACK_CHECK=$(uv run black --check src/ tests/ 2>&1)
    if [ $? -eq 0 ]; then
        echo "Black formatting: ✅ All files formatted"
    else
        echo "Black formatting: ❌ Files need formatting"
    fi
fi
echo ""

# 6. Git Status
echo "🔀 GIT STATUS"
echo "────────────────"
MODIFIED=$(git status --porcelain 2>/dev/null | wc -l)
BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
echo "Current branch: $BRANCH"
echo "Modified files: $MODIFIED"
echo ""

# 7. Session Context
echo "📝 SESSION CONTEXT"
echo "────────────────"
if [ -f ".claude/context/session.md" ]; then
    echo "Active session found"
    grep "^## Current Session" -A 3 .claude/context/session.md 2>/dev/null | tail -3
else
    echo "No active session context"
fi
echo ""

# 8. Research Reports
echo "🔬 RESEARCH REPORTS"
echo "────────────────"
if [ -d ".claude/research" ]; then
    REPORT_COUNT=$(ls -1 .claude/research/*.md 2>/dev/null | wc -l)
    echo "Reports available: $REPORT_COUNT"
    ls -1t .claude/research/*.md 2>/dev/null | head -3 | sed 's/.*\//  - /'
else
    echo "No research reports found"
fi
echo ""

# 9. Performance Metrics
echo "⚡ PERFORMANCE TARGETS"
echo "────────────────"
echo "Target: 5-min audio < 30s processing"
echo "Target: Memory < 2GB"
echo "Target: Accuracy > 95%"
echo "Target: Files < 300 lines"
echo ""

echo "═══════════════════════════════════════════════════════"
echo "Run './scripts/progress_tracker.sh' for updates"
echo "═══════════════════════════════════════════════════════"