#!/bin/bash

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

echo -e "${BLUE}=========================================${NC}"
echo -e "${BLUE}  Payload CMS MCP Server Global Installer ${NC}"
echo -e "${BLUE}=========================================${NC}"
echo ""

echo -e "${YELLOW}This script will install payload-cms-mcp globally on your system.${NC}"
echo -e "${YELLOW}You will be able to run it from anywhere using the 'payload-cms-mcp' command.${NC}"
echo ""

# Check if npm is installed
if ! command -v npm &> /dev/null; then
    echo -e "${RED}npm is not installed. Please install Node.js and npm first.${NC}"
    echo "Visit https://nodejs.org/ for installation instructions."
    exit 1
fi

echo -e "${BLUE}Installing payload-cms-mcp globally...${NC}"
npm install -g payload-cms-mcp

if [ $? -eq 0 ]; then
    echo -e "${GREEN}Installation successful!${NC}"
    echo ""
    echo -e "${BLUE}=== Usage Information ===${NC}"
    echo -e "You can now run the Payload CMS MCP Server from anywhere using:"
    echo -e "  ${GREEN}payload-cms-mcp${NC}"
    echo ""
    echo -e "${YELLOW}Note: You will still need Redis running for the server to work properly.${NC}"
    echo -e "You can run Redis using Docker:"
    echo -e "  ${BLUE}docker run -p 6379:6379 redis:alpine${NC}"
    echo ""
    echo -e "${GREEN}Thank you for installing Payload CMS MCP Server!${NC}"
else
    echo -e "${RED}Installation failed. Please check the error messages above.${NC}"
    exit 1
fi 