#!/bin/bash

# This script deploys the RealtimeCursor SDK and backend server

if [ "$#" -lt 1 ]; then
  echo "Usage: $0 <platform>"
  echo "Platforms: render, docker, manual"
  exit 1
fi

PLATFORM=$1

case $PLATFORM in
  render)
    echo "Deploying to Render..."
    echo "Make sure you have the Render CLI installed and are logged in."
    render deploy
    ;;
  
  docker)
    echo "Deploying with Docker..."
    
    # Build the SDK for CDN
    echo "Building SDK for CDN..."
    cd sdk
    ./build-cdn.sh
    cd ..
    
    # Build and start the Docker containers
    echo "Building and starting Docker containers..."
    docker-compose up -d --build
    
    echo "Deployment complete!"
    echo "Backend server: http://localhost:3000"
    echo "Demo page: http://localhost:80"
    ;;
  
  manual)
    echo "Manual deployment instructions:"
    echo ""
    echo "1. Build the SDK:"
    echo "   cd sdk"
    echo "   npm run build"
    echo "   ./build-cdn.sh"
    echo ""
    echo "2. Deploy the backend server:"
    echo "   - Copy the entire project to your server"
    echo "   - Install dependencies: npm install"
    echo "   - Start the server: node api/server.js"
    echo ""
    echo "3. Deploy the demo page:"
    echo "   - Copy the demo directory to your web server"
    echo "   - Copy the sdk/dist-cdn directory to your web server"
    echo "   - Update the API URL in demo/index.html"
    echo ""
    echo "4. Publish the SDK to npm:"
    echo "   cd sdk"
    echo "   ./publish.sh"
    ;;
  
  *)
    echo "Unknown platform: $PLATFORM"
    echo "Supported platforms: render, docker, manual"
    exit 1
    ;;
esac