#!/bin/bash

# Drama Ling 專案管理工具 - 統一入口點
# 使用方法: ./drama [命令]

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TOOLS_DIR="$SCRIPT_DIR/tools"

# 顏色定義
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
NC='\033[0m'

# 顯示主選單
show_menu() {
    echo -e "${BLUE}🎭 Drama Ling 管理工具${NC}"
    echo "=================================="
    echo ""
    echo -e "${PURPLE}📋 問題管理${NC}"
    echo "  issue       - 互動式問題管理"
    echo "  check       - 檢查問題狀態"
    echo ""
    echo -e "${PURPLE}📊 報告系統${NC}"
    echo "  report      - 建立分析報告"
    echo "  decision    - 建立決策記錄"  
    echo "  reports     - 檢查報告狀態"
    echo ""
    echo -e "${PURPLE}🚀 專案執行管理${NC}"
    echo "  project     - 專案管理"
    echo "  phase       - 階段管理"
    echo "  status      - 查看執行狀態"
    echo ""
    echo -e "${PURPLE}🔧 系統檢查${NC}"
    echo "  consistency - 執行一致性檢查"
    echo "  compliance  - 執行合規性檢查"
    echo "  all         - 執行全部檢查"
    echo ""
    echo -e "${PURPLE}⚙️ 系統設置${NC}"
    echo "  setup       - 設置全域命令別名"
    echo "  help        - 顯示此幫助"
    echo ""
    echo -e "${BLUE}範例:${NC}"
    echo "  ./dl issue             # 管理問題"
    echo "  ./dl report \"API分析\"    # 建立分析報告"
    echo "  ./dl project list      # 列出所有專案"
    echo "  ./dl phase status      # 查看階段狀態"
}

# 主邏輯
case "$1" in
    "issue")
        exec "$TOOLS_DIR/issue.sh"
        ;;
    "check")
        exec "$TOOLS_DIR/check_issues.sh"
        ;;
    "report")
        shift
        exec "$TOOLS_DIR/create_report.sh" analysis "$@"
        ;;
    "decision")
        shift  
        exec "$TOOLS_DIR/create_report.sh" decision "$@"
        ;;
    "reports")
        exec "$TOOLS_DIR/check_reports.sh"
        ;;
    "project")
        shift
        exec "$TOOLS_DIR/project.sh" "$@"
        ;;
    "phase")
        shift
        exec "$TOOLS_DIR/phase.sh" "$@"
        ;;
    "status")
        exec "$TOOLS_DIR/project.sh" status
        ;;
    "consistency")
        exec "$SCRIPT_DIR/scripts/maintenance_manager.sh" consistency
        ;;
    "compliance")
        exec "$TOOLS_DIR/check_compliance.sh"
        ;;
    "all")
        exec "$SCRIPT_DIR/scripts/maintenance_manager.sh" all
        ;;
    "setup")
        exec "$TOOLS_DIR/setup_aliases.sh"
        ;;
    "help"|"--help"|"-h")
        show_menu
        ;;
    "")
        show_menu
        ;;
    *)
        echo -e "${YELLOW}❌ 未知命令: $1${NC}"
        echo ""
        show_menu
        exit 1
        ;;
esac