#!/bin/bash

# CMS End-to-End Testing - Quick Commands
# Linear Issue: 09-158
# Usage: Source this file or copy commands as needed

BASE_URL="http://localhost:8000"
API_PREFIX="/api/admin"

echo "🚀 CMS E2E Testing Quick Commands"
echo "=================================="
echo ""

# Color codes
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# ==========================================
# BLOG CATEGORIES
# ==========================================
echo -e "${BLUE}📚 BLOG CATEGORIES${NC}"
echo ""

echo -e "${GREEN}1. Create Blog Category:${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/blog-categories \\"
echo "  -H 'Content-Type: application/json' \\"
echo "  -d '{\"name\":\"Technology\",\"status\":1}'"
echo ""

echo -e "${GREEN}2. List Blog Categories:${NC}"
echo "curl ${BASE_URL}${API_PREFIX}/blog-categories"
echo ""

echo -e "${GREEN}3. Toggle Category Status:${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/blog-categories/{id}/toggle-status"
echo ""

# ==========================================
# BLOG POSTS
# ==========================================
echo -e "${BLUE}✍️ BLOG POSTS${NC}"
echo ""

echo -e "${GREEN}4. Create Blog with Image:${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/blogs \\"
echo "  -F 'category_id=1' \\"
echo "  -F 'title=Test Blog Post' \\"
echo "  -F 'description=<p>Full blog content here</p>' \\"
echo "  -F 'image=@test-image.jpg' \\"
echo "  -F 'is_published=1' \\"
echo "  -F 'show_on_homepage=1' \\"
echo "  -F 'status=1'"
echo ""

echo -e "${GREEN}5. List All Blogs:${NC}"
echo "curl ${BASE_URL}${API_PREFIX}/blogs"
echo ""

echo -e "${GREEN}6. Search Blogs:${NC}"
echo "curl '${BASE_URL}${API_PREFIX}/blogs?search=test'"
echo ""

echo -e "${GREEN}7. Filter Blogs by Category:${NC}"
echo "curl '${BASE_URL}${API_PREFIX}/blogs?category_id=1'"
echo ""

echo -e "${GREEN}8. Get Blog by Slug (Public - Increments Views):${NC}"
echo "curl ${BASE_URL}/api/blogs/test-blog-post"
echo ""

echo -e "${GREEN}9. Update Blog (Keep Old Image):${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/blogs/{id} \\"
echo "  -H 'Content-Type: application/json' \\"
echo "  -d '{\"title\":\"Updated Title\",\"description\":\"Updated content\"}'"
echo ""

echo -e "${GREEN}10. Update Blog (Replace Image):${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/blogs/{id} \\"
echo "  -F 'title=Updated Title' \\"
echo "  -F 'image=@new-image.jpg'"
echo ""

echo -e "${YELLOW}Verify old image deleted from storage/app/public/blogs/${NC}"
echo ""

echo -e "${GREEN}11. Toggle Blog Status:${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/blogs/{id}/toggle-status"
echo ""

echo -e "${GREEN}12. Delete Blog:${NC}"
echo "curl -X DELETE ${BASE_URL}${API_PREFIX}/blogs/{id}"
echo ""

echo -e "${YELLOW}Verify image deleted from storage/app/public/blogs/${NC}"
echo ""

echo -e "${GREEN}13. Verify Public Blog Display:${NC}"
echo "curl ${BASE_URL}/api/blogs/{slug}"
echo ""

# ==========================================
# GALLERIES
# ==========================================
echo -e "${BLUE}🖼️ GALLERIES${NC}"
echo ""

echo -e "${GREEN}14. Create Gallery with 5 Images:${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/galleries \\"
echo "  -F 'title=Test Gallery 2025' \\"
echo "  -F 'description=Event photos gallery' \\"
echo "  -F 'images[]=@image1.jpg' \\"
echo "  -F 'images[]=@image2.jpg' \\"
echo "  -F 'images[]=@image3.jpg' \\"
echo "  -F 'images[]=@image4.jpg' \\"
echo "  -F 'images[]=@image5.jpg' \\"
echo "  -F 'is_active=1'"
echo ""

echo -e "${GREEN}15. List Galleries:${NC}"
echo "curl ${BASE_URL}${API_PREFIX}/galleries"
echo ""

echo -e "${GREEN}16. Get Single Gallery:${NC}"
echo "curl ${BASE_URL}${API_PREFIX}/galleries/{id}"
echo ""

echo -e "${GREEN}17. Add 3 More Images:${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/galleries/{id}/images \\"
echo "  -F 'images[]=@image6.jpg' \\"
echo "  -F 'images[]=@image7.jpg' \\"
echo "  -F 'images[]=@image8.jpg'"
echo ""

echo -e "${GREEN}18. Delete Specific Image:${NC}"
echo "curl -X DELETE ${BASE_URL}${API_PREFIX}/galleries/{id}/images \\"
echo "  -H 'Content-Type: application/json' \\"
echo "  -d '{\"image_path\":\"galleries/1/image1.jpg\"}'"
echo ""

echo -e "${YELLOW}Repeat for second image${NC}"
echo ""

echo -e "${GREEN}19. Update Gallery Details:${NC}"
echo "curl -X PUT ${BASE_URL}${API_PREFIX}/galleries/{id} \\"
echo "  -H 'Content-Type: application/json' \\"
echo "  -d '{\"title\":\"Updated Gallery Title\",\"description\":\"Updated description\"}'"
echo ""

echo -e "${GREEN}20. Toggle Gallery Status:${NC}"
echo "curl -X POST ${BASE_URL}${API_PREFIX}/galleries/{id}/toggle-status"
echo ""

echo -e "${GREEN}21. Delete Gallery:${NC}"
echo "curl -X DELETE ${BASE_URL}${API_PREFIX}/galleries/{id}"
echo ""

echo -e "${YELLOW}Verify all images deleted from storage/app/public/galleries/{id}/${NC}"
echo ""

echo -e "${GREEN}22. Verify Public Gallery Display:${NC}"
echo "curl ${BASE_URL}/api/galleries/{id}"
echo ""

# ==========================================
# CONTENT PAGES
# ==========================================
echo -e "${BLUE}📄 CONTENT PAGES${NC}"
echo ""

echo -e "${GREEN}23. Verify Public Page Display:${NC}"
echo "curl ${BASE_URL}/api/pages/{slug}"
echo ""

echo -e "${YELLOW}Replace {slug} with an actual page slug (e.g., 'about-us')${NC}"
echo ""

# ==========================================
# UTILITY COMMANDS
# ==========================================
echo -e "${BLUE}🔧 UTILITY COMMANDS${NC}"
echo ""

echo -e "${GREEN}Monitor Blog Images:${NC}"
echo "watch -n 1 'ls -lah storage/app/public/blogs/'"
echo ""

echo -e "${GREEN}Monitor Gallery Images:${NC}"
echo "watch -n 1 'ls -lah storage/app/public/galleries/'"
echo ""

echo -e "${GREEN}Check Laravel Logs:${NC}"
echo "tail -f storage/logs/laravel.log"
echo ""

echo -e "${GREEN}Create Test Images (requires ImageMagick):${NC}"
echo "convert -size 800x600 xc:blue test1.jpg"
echo "convert -size 800x600 xc:red test2.jpg"
echo ""

echo -e "${GREEN}Run Automated Test Suite:${NC}"
echo "php artisan test:cms"
echo ""

# ==========================================
# VERIFICATION CHECKLIST
# ==========================================
echo -e "${BLUE}✅ VERIFICATION CHECKLIST${NC}"
echo ""

echo "Blog Categories (3 tests):"
echo "  [ ] Create category"
echo "  [ ] List categories"
echo "  [ ] Toggle status"
echo ""

echo "Blog Posts (10 tests):"
echo "  [ ] Create with image"
echo "  [ ] List blogs"
echo "  [ ] Search blogs"
echo "  [ ] Filter by category"
echo "  [ ] Get by slug (public)"
echo "  [ ] Verify view count increment"
echo "  [ ] Update (keep image)"
echo "  [ ] Update (replace image)"
echo "  [ ] Toggle status"
echo "  [ ] Delete (verify image deleted)"
echo ""

echo "Galleries (9 tests):"
echo "  [ ] Create with 5 images"
echo "  [ ] List galleries"
echo "  [ ] Get single gallery"
echo "  [ ] Add 3 more images"
echo "  [ ] Delete 2 images"
echo "  [ ] Update details"
echo "  [ ] Toggle status"
echo "  [ ] Delete gallery (verify all images deleted)"
echo "  [ ] Verify public display"
echo ""

echo "Content Pages (1 test):"
echo "  [ ] Verify public display at /pages/{slug}"
echo ""

echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}Total Tests: 23${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"

# ==========================================
# NOTES
# ==========================================
echo ""
echo -e "${YELLOW}📝 NOTES:${NC}"
echo "  1. Replace {id} with actual IDs from responses"
echo "  2. Replace {slug} with actual slugs"
echo "  3. Admin endpoints require authentication (JWT token)"
echo "  4. Public endpoints (/api/blogs, /api/galleries, /api/pages) don't require auth"
echo "  5. View count only increments via public endpoint (/api/blogs/{slug})"
echo "  6. Images automatically deleted when parent entity is deleted or replaced"
echo ""

echo -e "${GREEN}For detailed documentation, see:${NC}"
echo "  - CMS_E2E_TEST_CHECKLIST.md"
echo "  - CMS_TESTING_SUMMARY.md"
echo ""
