#!/bin/bash
# 15_full_workflow.sh - זרימת עבודה מלאה: מ-main ועד PR

# === שלב 1: סנכרון main ===
git switch main
git pull

# === שלב 2: יצירת branch לפיצ'ר ===
git switch -c feature/user-profile

# === שלב 3: עבודה עם commits אטומיים ===
echo "<UserProfile />" > UserProfile.jsx
git add UserProfile.jsx
git commit -m "Add UserProfile component skeleton"

echo "fetch user data" > userApi.js
git add userApi.js
git commit -m "Add user API client"

echo "wire data to UI" > UserProfile.jsx
git add UserProfile.jsx
git commit -m "Wire user data to UserProfile component"

# === שלב 4: סנכרון תכוף עם main ===
git fetch origin
git rebase origin/main

# אם יש קונפליקטים - פותרים
# git add <files>
# git rebase --continue

# === שלב 5: דחיפה ראשונה ===
git push -u origin feature/user-profile

# === שלב 6: עבודה נוספת לאחר feedback ===
echo "improvements" >> UserProfile.jsx
git add UserProfile.jsx
git commit -m "Address PR feedback: extract avatar component"

# === שלב 7: דחיפה רגילה ===
git push

# === שלב 8: יצירת PR מ-CLI ===
gh pr create --title "Add user profile page" --body "$(cat <<'EOF'
## Summary
- Add UserProfile component with avatar and bio
- Wire to /api/users/me endpoint
- Add edit modal

## Test plan
- [ ] Verify profile loads
- [ ] Test edit flow
- [ ] Check error states
EOF
)"

# === שלב 9: אחרי merge - ניקוי ===
git switch main
git pull
git branch -d feature/user-profile

# branches מרוחקים שנמחקו - ניקוי מקומי
git fetch --prune
