#!/bin/bash
set -e

echo "=== WALL-E Cloud Deployment ==="
echo ""

# Check fly CLI
if ! command -v fly &> /dev/null; then
  echo "Error: fly CLI not installed. Run: brew install flyctl"
  exit 1
fi

# Check if app exists
if ! fly apps list 2>/dev/null | grep -q my-wall-e; then
  echo "Creating Fly.io app..."
  fly apps create my-wall-e
  fly volumes create wall_e_data --region sjc --size 5
fi

# Set secrets
echo "Setting secrets..."
echo "Make sure to set ANTHROPIC_API_KEY or Portkey headers:"
echo "  fly secrets set ANTHROPIC_API_KEY=sk-..."
echo "  fly secrets set ANTHROPIC_BASE_URL=https://..."
echo "  fly secrets set ANTHROPIC_CUSTOM_HEADERS_B64=..."
echo ""

# Deploy
echo "Deploying..."
fly deploy

echo ""
echo "=== Deployment complete ==="
echo "WALL-E is running at: https://my-wall-e.fly.dev"
echo "Health check: https://my-wall-e.fly.dev/api/wall-e/health"
