#!/bin/bash

# Roadcrew Setup Script
# Automates the installation of Roadcrew as a git submodule in your project
# Usage: ./setup.sh

set -e

echo ""
echo "🚀 Setting up Roadcrew..."
echo ""

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

# Check if we're in a git repository
if [ ! -d ".git" ]; then
  echo -e "${RED}❌ Error: Not in a git repository${NC}"
  echo "Please initialize git first: git init"
  exit 1
fi

# Step 1: Add Roadcrew submodule
echo -e "${BLUE}Step 1: Adding Roadcrew as git submodule...${NC}"
if [ -d ".roadcrew" ]; then
  echo -e "${RED}❌ Error: .roadcrew directory already exists${NC}"
  echo "Remove it first: rm -rf .roadcrew"
  exit 1
fi

git submodule add git@github.com:tailwind-ai/roadcrew.git .roadcrew
echo -e "${GREEN}✓ Submodule added${NC}"
echo ""

# Step 2: Initialize submodule
echo -e "${BLUE}Step 2: Initializing submodule...${NC}"
git submodule update --init --recursive
echo -e "${GREEN}✓ Submodule initialized${NC}"
echo ""

# Step 3: Run installation
echo -e "${BLUE}Step 3: Running Roadcrew installation...${NC}"
node .roadcrew/install.cjs

if [ $? -eq 0 ]; then
  echo ""
  echo -e "${GREEN}✅ Roadcrew setup complete!${NC}"
  echo ""
  echo "Next steps:"
  echo "  1. Review the generated files in .roadcrew/"
  echo "  2. Read .roadcrew/.memory/01-brief.md for project status"
  echo "  3. Commit: git add .gitmodules .roadcrew && git commit -m 'Add Roadcrew'"
  echo "  4. Run: /onboard to set up project context"
  echo "  5. Start using Roadcrew commands in Cursor!"
  echo ""
else
  echo -e "${RED}❌ Installation failed${NC}"
  exit 1
fi
