#!/bin/bash

# Automated release creation script
set -e

VERSION=${1:-"0.1.0"}

echo "📦 Creating Release v${VERSION}"
echo "=============================="
echo ""

# Check if we're in a git repo
if [ ! -d .git ]; then
    echo "❌ Not in a git repository"
    exit 1
fi

# Check if there are uncommitted changes
if ! git diff-index --quiet HEAD --; then
    echo "❌ You have uncommitted changes. Commit or stash them first."
    exit 1
fi

# Update version in Cargo.toml
echo "1️⃣ Updating version in Cargo.toml..."
if [[ "$OSTYPE" == "darwin"* ]]; then
    sed -i '' "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml
else
    sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml
fi

# Update Cargo.lock
echo "2️⃣ Updating Cargo.lock..."
cargo check > /dev/null 2>&1

# Commit version bump
echo "3️⃣ Committing version bump..."
git add Cargo.toml Cargo.lock
git commit -m "chore: bump version to ${VERSION}" || echo "No changes to commit"

# Create tag
echo "4️⃣ Creating git tag..."
git tag -a "v${VERSION}" -m "Release v${VERSION}

## What's New
- Watch mode for automatic clipboard-to-path conversion
- Desktop symlinks for easy access
- Cross-platform clipboard monitoring
- MCP server integration for Claude Code

## Installation
\`\`\`bash
# Homebrew
brew tap josharsh/claude-utils
brew install claude-utils

# Cargo
cargo install claude-utils

# Direct download
See release assets below
\`\`\`

## Usage
\`\`\`bash
# Start with watch mode
claude-utils start --watch

# Copy any image, then press Cmd+V in terminal
# Path appears like magic! 🪄
\`\`\`"

echo "✅ Tag created: v${VERSION}"
echo ""
echo "5️⃣ Next steps:"
echo "   git push origin main"
echo "   git push origin v${VERSION}"
echo ""
echo "This will trigger GitHub Actions to build binaries!"