# Move Inquiry AI Analysis to Celery Task

## Summary
Replace synchronous AI calls in 3 inquiry creation views with the existing `analyze_inquiry_with_ai.delay()` Celery task.

## Changes

### 1. `apps/complaints/ui_views.py` — `inquiry_create` (lines 1554-1567)

**Replace:**
```python
                from apps.complaints.tasks import _apply_inquiry_ai_analysis
                from apps.core.ai_service import AIService

                try:
                    analysis = AIService.analyze_inquiry(
                        subject=inquiry.subject,
                        message=inquiry.message,
                        category=inquiry.get_category_display(),
                        hospital_id=inquiry.hospital.id,
                    )
                    emotion_analysis = AIService.analyze_emotion(text=inquiry.message)
                    _apply_inquiry_ai_analysis(inquiry, analysis, emotion_analysis)
                except Exception as e:
                    logger.error(f"AI analysis failed on inquiry creation: {e}")
```

**With:**
```python
                from apps.complaints.tasks import analyze_inquiry_with_ai

                analyze_inquiry_with_ai.delay(str(inquiry.id))
```

Also update line 1572 — change `"Inquiry created with AI analysis."` to `"Inquiry created."`

---

### 2. `apps/complaints/ui_views.py` — `public_inquiry_submit` (lines 2315-2328)

**Replace:**
```python
            from apps.complaints.tasks import _apply_inquiry_ai_analysis
            from apps.core.ai_service import AIService

            try:
                analysis = AIService.analyze_inquiry(
                    subject=inquiry.subject,
                    message=inquiry.message,
                    category=category,
                    hospital_id=hospital.id,
                )
                emotion_analysis = AIService.analyze_emotion(text=inquiry.message)
                _apply_inquiry_ai_analysis(inquiry, analysis, emotion_analysis)
            except Exception as e:
                logger.error(f"AI analysis failed on public inquiry creation: {e}")
```

**With:**
```python
            from apps.complaints.tasks import analyze_inquiry_with_ai

            analyze_inquiry_with_ai.delay(str(inquiry.id))
```

---

### 3. `apps/complaints/views.py` — `InquiryViewSet.perform_create` (lines 2750-2763)

**Replace:**
```python
        from apps.complaints.tasks import _apply_inquiry_ai_analysis
        from apps.core.ai_service import AIService

        try:
            analysis = AIService.analyze_inquiry(
                subject=inquiry.subject,
                message=inquiry.message,
                category=inquiry.get_category_display(),
                hospital_id=inquiry.hospital.id,
            )
            emotion_analysis = AIService.analyze_emotion(text=inquiry.message)
            _apply_inquiry_ai_analysis(inquiry, analysis, emotion_analysis)
        except Exception as e:
            logger.error(f"AI analysis failed on inquiry creation: {e}")
```

**With:**
```python
        from apps.complaints.tasks import analyze_inquiry_with_ai

        analyze_inquiry_with_ai.delay(str(inquiry.id))
```

Also update docstring on line 2747 from `"Auto-set created_by from request.user and run AI analysis synchronously"` to `"Auto-set created_by from request.user and trigger AI analysis in background"`.
