#!/bin/bash

# Post-release automation
set -e

VERSION=${1:-"0.1.0"}
GITHUB_USER=${2:-"josharsh"}

echo "🎉 Post-Release Tasks for v${VERSION}"
echo "===================================="
echo ""

# Wait for GitHub Actions to complete
echo "1️⃣ Waiting for GitHub Actions to build binaries..."
echo "   Check: https://github.com/${GITHUB_USER}/claude-utils/actions"
echo ""
read -p "Press Enter when builds are complete..."

# Update Homebrew formula
echo ""
echo "2️⃣ Updating Homebrew formula..."
./scripts/create-homebrew-formula.sh "$VERSION"
echo "✅ Formula updated with real SHA256 values"

# Generate install script
echo ""
echo "3️⃣ Creating install script..."
cat > install.sh << 'EOF'
#!/bin/bash
# Claude-Utils Quick Install Script

set -e

echo "Installing Claude-Utils..."

# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case "$OS" in
    darwin)
        PLATFORM="macos"
        case "$ARCH" in
            arm64) ARCH_SUFFIX="arm64" ;;
            x86_64) ARCH_SUFFIX="x64" ;;
            *) echo "Unsupported architecture: $ARCH"; exit 1 ;;
        esac
        ;;
    linux)
        PLATFORM="linux"
        ARCH_SUFFIX="x64"
        ;;
    *)
        echo "Unsupported OS: $OS"
        exit 1
        ;;
esac

# Get latest release
LATEST=$(curl -s https://api.github.com/repos/josharsh/claude-utils/releases/latest | grep "tag_name" | cut -d '"' -f 4)
DOWNLOAD_URL="https://github.com/josharsh/claude-utils/releases/download/${LATEST}/claude-utils-${PLATFORM}-${ARCH_SUFFIX}.tar.gz"

# Download and install
echo "Downloading from: $DOWNLOAD_URL"
curl -L "$DOWNLOAD_URL" | tar xz

# Install to /usr/local/bin
echo "Installing to /usr/local/bin (requires sudo)..."
sudo mv claude-utils /usr/local/bin/

echo "✅ Claude-Utils installed successfully!"
echo ""
echo "Get started:"
echo "  claude-utils start --watch"
EOF

chmod +x install.sh
echo "✅ install.sh created"

# Create announcement template
echo ""
echo "4️⃣ Creating announcement template..."
cat > ANNOUNCEMENT.md << EOF
# 🎉 Claude-Utils v${VERSION} Released!

Seamless clipboard integration for Claude Code is here!

## ✨ What's New

**Watch Mode** - The killer feature:
- Copy any image → Automatically saved with Desktop symlink
- Press ⌘V in terminal → File path appears!
- Original image still available for other apps

## 🚀 Quick Start

\`\`\`bash
# macOS/Linux (Homebrew)
brew tap ${GITHUB_USER}/claude-utils
brew install claude-utils

# All platforms (Cargo)
cargo install claude-utils

# Direct download
curl -sSL https://raw.githubusercontent.com/${GITHUB_USER}/claude-utils/main/install.sh | bash
\`\`\`

## 📸 Demo

1. Start watch mode: \`claude-utils start --watch\`
2. Copy any image (screenshot, etc.)
3. In terminal: ⌘V → \`/Users/you/Desktop/claude-paste.png\`
4. In Claude Code: "Analyze the image at ~/Desktop/claude-paste.png"

## 🔗 Links

- GitHub: https://github.com/${GITHUB_USER}/claude-utils
- Docs: https://github.com/${GITHUB_USER}/claude-utils#readme
- Issues: https://github.com/${GITHUB_USER}/claude-utils/issues

Made with ❤️ for the Claude Code community
EOF

echo "✅ ANNOUNCEMENT.md created"
echo ""
echo "5️⃣ Next steps:"
echo "   - Update Homebrew tap with new formula"
echo "   - Post announcement to:"
echo "     - Dev.to"
echo "     - Reddit (r/rust, r/commandline)"
echo "     - Twitter/X"
echo "     - Discord/Slack communities"
echo ""
echo "6️⃣ Monitor:"
echo "   - GitHub issues"
echo "   - Crates.io downloads"
echo "   - Community feedback"