#!/bin/bash
# Claude Code Settings Optimizer - Installation Script

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLAUDE_DIR="${HOME}/.claude"

echo "Claude Code Settings Optimizer - Installer"
echo "==========================================="
echo ""

# Create directories
echo "Creating directories..."
mkdir -p "${CLAUDE_DIR}/commands"
mkdir -p "${CLAUDE_DIR}/scripts/settings-audit"
mkdir -p "${CLAUDE_DIR}/references"

# Install command
echo "Installing /settings-audit command..."
cp "${SCRIPT_DIR}/commands/settings-audit.md" "${CLAUDE_DIR}/commands/"

# Install scripts
echo "Installing scripts..."
cp "${SCRIPT_DIR}/scripts/"*.py "${CLAUDE_DIR}/scripts/settings-audit/"
chmod +x "${CLAUDE_DIR}/scripts/settings-audit/"*.py

# Install references
echo "Installing references..."
cp "${SCRIPT_DIR}/references/"*.md "${CLAUDE_DIR}/references/"

# Check Python
echo ""
echo "Checking Python..."
if command -v python3 &> /dev/null; then
    echo "  Python 3: $(python3 --version)"
else
    echo "  Warning: Python 3 not found"
fi

# Check PyYAML (optional)
if python3 -c "import yaml" 2>/dev/null; then
    echo "  PyYAML: installed"
else
    echo "  PyYAML: not installed (optional)"
    echo "  Install with: pip3 install pyyaml"
fi

echo ""
echo "Installation complete!"
echo ""
echo "Installed to:"
echo "  Command:    ${CLAUDE_DIR}/commands/settings-audit.md"
echo "  Scripts:    ${CLAUDE_DIR}/scripts/settings-audit/"
echo "  References: ${CLAUDE_DIR}/references/"
echo ""
echo "Usage:"
echo "  In Claude Code: /settings-audit"
echo ""
echo "  Or run directly:"
echo "  python3 ${CLAUDE_DIR}/scripts/settings-audit/run_audit.py"
echo ""
echo "  Auto-fix (preview):"
echo "  python3 ${CLAUDE_DIR}/scripts/settings-audit/auto_fix.py"
echo ""
echo "  Auto-fix (apply):"
echo "  python3 ${CLAUDE_DIR}/scripts/settings-audit/auto_fix.py --apply"
echo ""
