#!/bin/bash
# Install script for Agentic Engineering Skill Kits
# Usage: bash install.sh [kit-name]
# If no kit name specified, installs all kits

set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

KIT_NAME="${1:-all}"
SKILLS_DIR="$(cd "$(dirname "$0")/.." && pwd)"

echo -e "${GREEN}Agentic Engineering Skill Kits Installer${NC}"
echo "Source: $SKILLS_DIR"
echo "Kit: $KIT_NAME"
echo ""

install_kit() {
    local kit_path="$1"
    local kit_name=$(basename "$kit_path")
    
    echo -e "${YELLOW}Installing kit: $kit_name${NC}"
    
    # Install skills
    if [ -d "$kit_path/skills" ]; then
        for skill in "$kit_path/skills"/*/; do
            skill_name=$(basename "$skill")
            echo "  Installing skill: $skill_name"
            
            # Claude Code
            mkdir -p ~/.claude/skills/"$skill_name"
            cp -r "$skill"/* ~/.claude/skills/"$skill_name"/
            echo "    → ~/.claude/skills/$skill_name/"
            
            # Pi Agent
            mkdir -p ~/.pi/skills/"$skill_name"
            cp -r "$skill"/* ~/.pi/skills/"$skill_name"/
            echo "    → ~/.pi/skills/$skill_name/"
        done
    fi
    
    # Install extensions
    if [ -d "$kit_path/extensions" ]; then
        for ext in "$kit_path/extensions"/*.ts; do
            if [ -f "$ext" ]; then
                ext_name=$(basename "$ext")
                echo "  Installing extension: $ext_name"
                mkdir -p ~/.pi/extensions/
                cp "$ext" ~/.pi/extensions/"$ext_name"
                echo "    → ~/.pi/extensions/$ext_name"
            fi
        done
    fi
    
    echo -e "${GREEN}  ✓ Kit installed: $kit_name${NC}"
    echo ""
}

if [ "$KIT_NAME" = "all" ]; then
    for kit in "$SKILLS_DIR/kits"/*/; do
        if [ -d "$kit" ]; then
            install_kit "$kit"
        fi
    done
elif [ -d "$SKILLS_DIR/kits/$KIT_NAME" ]; then
    install_kit "$SKILLS_DIR/kits/$KIT_NAME"
else
    echo -e "${RED}Error: Kit '$KIT_NAME' not found${NC}"
    echo "Available kits:"
    for kit in "$SKILLS_DIR/kits"/*/; do
        echo "  $(basename "$kit")"
    done
    exit 1
fi

echo -e "${GREEN}Installation complete!${NC}"
echo ""
echo "To verify:"
echo "  ls ~/.claude/skills/"
echo "  ls ~/.pi/skills/"
echo "  ls ~/.pi/extensions/"
