#!/bin/bash
# MCP-ZERO Playground Integration for Burn Folder
# This script adds ZETA playground support to a burn folder

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

# Print colored message
print_message() {
  local color=$1
  local message=$2
  echo -e "${color}${message}${NC}"
}

# Integrate ZETA playground into burn folder
integrate_zeta_playground() {
  local TARGET_DIR=$1
  print_message "${BLUE}" "Integrating ZETA playground components..."
  
  # Create necessary directories
  mkdir -p "${TARGET_DIR}/logs"
  mkdir -p "${TARGET_DIR}/.mcpzero/playground"
  mkdir -p "${TARGET_DIR}/.mcpzero/lock"
  
  # Source directory
  SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  
  # Copy essential playground files for offline-first resilience
  if [ -f "${SOURCE_DIR}/burn_folder/.mcpzero/playground/zeta_playground.py" ]; then
    cp "${SOURCE_DIR}/burn_folder/.mcpzero/playground/zeta_playground.py" "${TARGET_DIR}/.mcpzero/playground/"
    print_message "${GREEN}" "ZETA playground integration files copied successfully."
  else
    print_message "${YELLOW}" "WARNING: ZETA playground integration files not found. Some agent features may be limited."
  fi
  
  # Create offline lock file template for offline-first resilience
  cat > "${TARGET_DIR}/.mcpzero/lock/offline.lock.template" << EOF
{
  "offline_mode": true,
  "timestamp": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
  "reason": "Offline-first operation enabled by burn configuration"
}
EOF
  chmod 444 "${TARGET_DIR}/.mcpzero/lock/offline.lock.template"
  
  print_message "${GREEN}" "ZETA playground components integrated successfully with offline-first resilience support."
}

# Export the function
export -f integrate_zeta_playground
