#!/bin/bash

# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Function to check if a command exists
command_exists() {
    command -v "$1" >/dev/null 2>&1
}

# Function to check dependencies
check_dependencies() {
    local missing_deps=()

    # Check for claude (required)
    if ! command_exists claude; then
        missing_deps+=("claude")
    fi

    # Check for jq (required for JSON output parsing)
    if ! command_exists jq; then
        missing_deps+=("jq")
    fi

    # Show critical errors
    if [ ${#missing_deps[@]} -ne 0 ]; then
        echo -e "${RED}❌ Missing required dependencies:${NC}"
        for dep in "${missing_deps[@]}"; do
            echo -e "  - $dep"
            if [ "$dep" = "claude" ]; then
                echo -e "    Install from: https://docs.anthropic.com/en/docs/claude-code"
            elif [ "$dep" = "jq" ]; then
                echo -e "    Install: brew install jq (macOS) or apt install jq (Linux)"
            fi
        done
        echo
        exit 1
    fi
}

# If sourced directly, run the check
if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
    check_dependencies "$@"
fi