#!/bin/bash

# Mock AI CLI Commands for Testing
# これらのスクリプトは実際のAI CLIコマンドをシミュレートします

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MOCK_BIN_DIR="$SCRIPT_DIR/mock-bin"

# Create mock binary directory
mkdir -p "$MOCK_BIN_DIR"

# Create mock qwen command
cat > "$MOCK_BIN_DIR/qwen" << 'EOF'
#!/bin/bash
# Mock Qwen CLI command

echo "🤖 Mock Qwen Response:" >&2
echo "Command: qwen $@" >&2

# Parse arguments
PROMPT=""
MODEL="qwen3-coder-plus"
SANDBOX=false
YOLO=false

while [[ $# -gt 0 ]]; do
    case $1 in
        -p|--prompt)
            PROMPT="$2"
            shift 2
            ;;
        -m|--model)
            MODEL="$2"
            shift 2
            ;;
        -s|--sandbox)
            SANDBOX=true
            shift
            ;;
        -y|--yolo)
            YOLO=true
            shift
            ;;
        *)
            shift
            ;;
    esac
done

# Generate mock response
echo "Hello from Qwen ($MODEL)!"
echo "Prompt: $PROMPT"
echo "Sandbox: $SANDBOX"
echo "Auto-accept: $YOLO"
echo ""
echo "This is a mock response for testing the AI CLI Hub integration."
echo "In a real implementation, this would be processed by Qwen's AI models."
EOF

# Create mock gemini command
cat > "$MOCK_BIN_DIR/gemini" << 'EOF'
#!/bin/bash
# Mock Gemini CLI command

echo "💎 Mock Gemini Response:" >&2
echo "Command: gemini $@" >&2

# Parse arguments
PROMPT=""
MODEL="gemini-2.5-pro"
GROUNDING=false

while [[ $# -gt 0 ]]; do
    case $1 in
        -p|--prompt)
            PROMPT="$2"
            shift 2
            ;;
        -m|--model)
            MODEL="$2"
            shift 2
            ;;
        --grounding)
            GROUNDING=true
            shift
            ;;
        --analysis-type)
            ANALYSIS_TYPE="$2"
            shift 2
            ;;
        *)
            shift
            ;;
    esac
done

# Generate mock response
echo "Hello from Gemini ($MODEL)!"
echo "Prompt: $PROMPT"
echo "Grounding: $GROUNDING"
if [ ! -z "$ANALYSIS_TYPE" ]; then
    echo "Analysis Type: $ANALYSIS_TYPE"
fi
echo ""
echo "This is a mock response demonstrating Gemini's advanced reasoning capabilities."
echo "Real Gemini would provide detailed analysis and code understanding."
EOF

# Create mock opencode command
cat > "$MOCK_BIN_DIR/opencode" << 'EOF'
#!/bin/bash
# Mock OpenCode CLI command

echo "🌐 Mock OpenCode Response:" >&2
echo "Command: opencode $@" >&2

# Parse arguments
PROMPT=""
PROVIDER="anthropic"
TASK_TYPE="chat"

while [[ $# -gt 0 ]]; do
    case $1 in
        -p|--prompt)
            PROMPT="$2"
            shift 2
            ;;
        --provider)
            PROVIDER="$2"
            shift 2
            ;;
        --task)
            TASK_TYPE="$2"
            shift 2
            ;;
        --language)
            LANGUAGE="$2"
            shift 2
            ;;
        *)
            shift
            ;;
    esac
done

# Generate mock response
echo "Hello from OpenCode ($PROVIDER)!"
echo "Prompt: $PROMPT"
echo "Task Type: $TASK_TYPE"
if [ ! -z "$LANGUAGE" ]; then
    echo "Language: $LANGUAGE"
fi
echo ""
echo "This is a mock response showing OpenCode's multi-provider AI integration."
echo "Real OpenCode would utilize multiple AI providers with fallback capabilities."
EOF

# Make all mock commands executable
chmod +x "$MOCK_BIN_DIR"/*

# Create a script to add mock commands to PATH
cat > "$SCRIPT_DIR/setup-mock-env.sh" << EOF
#!/bin/bash
# Setup script to add mock AI commands to PATH

export PATH="$MOCK_BIN_DIR:\$PATH"
echo "✅ Mock AI commands added to PATH"
echo "Available mock commands:"
echo "  - qwen (Mock Qwen CLI)"
echo "  - gemini (Mock Gemini CLI)" 
echo "  - opencode (Mock OpenCode CLI)"
echo ""
echo "To use in your shell:"
echo "  source $SCRIPT_DIR/setup-mock-env.sh"
echo ""
echo "To test commands:"
echo "  qwen -p 'Hello World'"
echo "  gemini -p 'Analyze this code'"
echo "  opencode -p 'Generate a function'"
EOF

chmod +x "$SCRIPT_DIR/setup-mock-env.sh"

echo "🎭 Mock AI CLI commands created successfully!"
echo ""
echo "📋 Created mock commands:"
echo "  - $MOCK_BIN_DIR/qwen"
echo "  - $MOCK_BIN_DIR/gemini"
echo "  - $MOCK_BIN_DIR/opencode"
echo ""
echo "🚀 To enable mock commands in your environment:"
echo "  source $SCRIPT_DIR/setup-mock-env.sh"
echo ""
echo "🧪 To test a mock command:"
echo "  $MOCK_BIN_DIR/qwen -p 'Hello from AI CLI Hub!'"