#!/bin/bash

# Generate all 30 MCP GitHub repos
# Format: {Software name} MCP 2026 Complete Version

set -e

WORKSPACE_DIR="/Users/jakeshore/.clawdbot/workspace"
REPOS_DIR="$WORKSPACE_DIR/mcp-github-repos"
SERVERS_DIR="$WORKSPACE_DIR/mcp-diagrams/mcp-servers"
TEMPLATE_DIR="$REPOS_DIR/servicetitan-mcp"

# Platform configurations: "directory-name|Display Name|waitlist-slug"
PLATFORMS=(
  "acuity-scheduling|Acuity Scheduling|acuity"
  "bamboohr|BambooHR|bamboohr"
  "basecamp|Basecamp|basecamp"
  "bigcommerce|BigCommerce|bigcommerce"
  "brevo|Brevo|brevo"
  "calendly|Calendly|calendly"
  "clickup|ClickUp|clickup"
  "close|Close CRM|closecrm"
  "clover|Clover|clover"
  "constant-contact|Constant Contact|constantcontact"
  "fieldedge|FieldEdge|fieldedge"
  "freshbooks|FreshBooks|freshbooks"
  "freshdesk|Freshdesk|freshdesk"
  "gusto|Gusto|gusto"
  "helpscout|Help Scout|helpscout"
  "housecall-pro|Housecall Pro|housecallpro"
  "jobber|Jobber|jobber"
  "keap|Keap|keap"
  "lightspeed|Lightspeed|lightspeed"
  "mailchimp|Mailchimp|mailchimp"
  "pipedrive|Pipedrive|pipedrive"
  "rippling|Rippling|rippling"
  "servicetitan|ServiceTitan|servicetitan"
  "squarespace|Squarespace|squarespace"
  "toast|Toast|toast"
  "touchbistro|TouchBistro|touchbistro"
  "trello|Trello|trello"
  "wave|Wave|wave"
  "wrike|Wrike|wrike"
  "zendesk|Zendesk|zendesk"
)

echo "🚀 Generating 30 MCP GitHub repos..."
echo ""

for platform_config in "${PLATFORMS[@]}"; do
  IFS='|' read -r dir_name display_name slug <<< "$platform_config"
  
  repo_name="${display_name// /-}-MCP-2026-Complete"
  repo_name_lower=$(echo "$repo_name" | tr '[:upper:]' '[:lower:]')
  repo_dir="$REPOS_DIR/$repo_name_lower"
  
  echo "📦 Processing: $display_name"
  echo "   Repo: $repo_name"
  echo "   Directory: $repo_name_lower"
  
  # Skip if already exists and has .git
  if [ -d "$repo_dir/.git" ]; then
    echo "   ⏭️  Skipping (already exists with git)"
    echo ""
    continue
  fi
  
  # Create repo directory
  mkdir -p "$repo_dir"
  
  # Check if source exists
  if [ ! -d "$SERVERS_DIR/$dir_name" ]; then
    echo "   ⚠️  Warning: Source not found at $SERVERS_DIR/$dir_name"
    echo ""
    continue
  fi
  
  # Copy source code
  if [ -d "$SERVERS_DIR/$dir_name/src" ]; then
    cp -r "$SERVERS_DIR/$dir_name/src" "$repo_dir/"
  fi
  
  if [ -f "$SERVERS_DIR/$dir_name/tsconfig.json" ]; then
    cp "$SERVERS_DIR/$dir_name/tsconfig.json" "$repo_dir/"
  fi
  
  echo "   ✅ Created structure"
done

echo ""
echo "✨ Phase 1 complete: Directory structure created"
echo "📝 Next: Generate READMEs and config files (run generate-readmes.js)"
