#!/bin/bash
# Git Repository Setup Script for Django Hooks

set -e  # Exit on error

echo "=========================================="
echo "Django Hooks - Git Repository Setup"
echo "=========================================="
echo ""

# Check if we're in the right directory
if [ ! -f "pyproject.toml" ] || [ ! -d "django_hooks" ]; then
    echo "❌ Error: Must run from django-hooks root directory"
    echo "   Expected to find: pyproject.toml and django_hooks/"
    exit 1
fi

# Initialize git if not already initialized
if [ ! -d ".git" ]; then
    echo "📦 Initializing git repository..."
    git init
    echo "✅ Git initialized"
else
    echo "ℹ️  Git already initialized"
fi

# Check git status
echo ""
echo "📊 Current git status:"
git status --short

# Add all files
echo ""
echo "➕ Adding files to git..."
git add .

# Show what will be committed
echo ""
echo "📝 Files to be committed:"
git diff --cached --stat

# Commit
echo ""
read -p "💬 Enter commit message (or press Enter for default): " commit_msg
if [ -z "$commit_msg" ]; then
    commit_msg="Initial commit: Django Hooks v1.0.0

- Two-phase hook system (PRE/POST)
- Priority-based execution
- Structured error codes
- Complete documentation
- Test examples
- Production-ready"
fi

git commit -m "$commit_msg"
echo "✅ Committed successfully"

# Show commit
echo ""
echo "📜 Commit details:"
git log -1 --oneline

# Tag version
echo ""
read -p "🏷️  Create version tag v1.0.0? (y/n): " create_tag
if [ "$create_tag" = "y" ] || [ "$create_tag" = "Y" ]; then
    git tag -a v1.0.0 -m "Version 1.0.0 - Initial release"
    echo "✅ Tag v1.0.0 created"
fi

# Show branches
echo ""
echo "🌿 Current branch:"
git branch

# Instructions for GitHub
echo ""
echo "=========================================="
echo "✅ Local Git Repository Ready!"
echo "=========================================="
echo ""
echo "📋 Next Steps:"
echo ""
echo "1. Create GitHub repository:"
echo "   • Go to https://github.com/new"
echo "   • Repository name: django-hooks"
echo "   • Description: Reusable hook system for Django packages"
echo "   • Keep it public or private"
echo "   • Do NOT initialize with README (we have one)"
echo ""
echo "2. Add remote and push:"
echo "   git remote add origin https://github.com/YOUR_USERNAME/django-hooks.git"
echo "   git branch -M main"
echo "   git push -u origin main"
if [ "$create_tag" = "y" ] || [ "$create_tag" = "Y" ]; then
    echo "   git push origin v1.0.0"
fi
echo ""
echo "3. To use in other projects:"
echo "   cd /path/to/your-project"
echo "   git submodule add https://github.com/YOUR_USERNAME/django-hooks.git libs/django-hooks"
echo ""
echo "=========================================="
echo ""
