#!/bin/bash
set -e

echo "📦 Publishing hyperscan-tokio v0.1.0 to crates.io"

# Dry run first
echo "🧪 Running dry-run for sys crate..."
cd hyperscan-tokio-sys
cargo publish --dry-run

echo ""
echo "🧪 Running dry-run for main crate..."
echo "Note: This will fail if sys crate isn't published yet, which is expected for first release"
cd ..
cargo publish --dry-run || true

echo ""
echo "✅ Dry run successful!"
echo ""
echo "Ready to publish? This will:"
echo "1. Publish hyperscan-tokio-sys to crates.io"
echo "2. Wait 30 seconds for crates.io to update"
echo "3. Publish hyperscan-tokio to crates.io"
echo ""
read -p "Continue? (y/N) " -n 1 -r
echo ""

if [[ $REPLY =~ ^[Yy]$ ]]
then
    echo "📤 Publishing sys crate..."
    cd hyperscan-tokio-sys
    cargo publish
    
    echo "⏳ Waiting 30 seconds for crates.io to update..."
    sleep 30
    
    echo "📤 Publishing main crate..."
    cd ..
    cargo publish
    
    echo ""
    echo "🎉 Published successfully!"
    echo "View at: https://crates.io/crates/hyperscan-tokio"
else
    echo "❌ Publishing cancelled"
fi