# Plan: Unify Department Response + Add Reporter Notifications

## Goal
1. Make all three types use the same department response approach (token-based, no login)
2. Add reporter notifications for complaint/inquiry when department responds

---

## 1. UNIFY DEPARTMENT RESPONSE (Token-Based for All)

### Current State
- **Complaint**: Uses `ComplaintExplanation` model with token links — champion clicks link, submits explanation without login
- **Observation**: Champion logs into system, navigates to department detail page, submits response via form
- **Inquiry**: Same as observation — login required

### Target State
All three use token-based links (like complaint):
- PX team sends to department → champion receives email with one-time link
- Champion clicks link → submits response without login
- Link expires after use

### Changes Needed

#### a) Create shared `DepartmentResponse` model (or reuse existing patterns)
Better approach: Create a token-based response flow for observation and inquiry similar to complaint's `ComplaintExplanation`.

**New model in `apps/organizations/models.py`** (or `apps/core/models.py`):
```python
class DepartmentResponseToken(UUIDModel, TimeStampedModel):
    """Token-based department response link for observations and inquiries."""
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.UUIDField()
    content_object = GenericForeignKey('content_type', 'object_id')
    
    department = models.ForeignKey('organizations.Department', on_delete=models.CASCADE)
    staff = models.ForeignKey('organizations.Staff', on_delete=models.CASCADE)
    token = models.CharField(max_length=100, unique=True)
    
    is_used = models.BooleanField(default=False)
    responded_at = models.DateTimeField(null=True, blank=True)
    
    # SLA
    sla_due_at = models.DateTimeField(null=True, blank=True)
    is_overdue = models.BooleanField(default=False)
    
    class Meta:
        indexes = [models.Index(fields=['token'])]
```

Actually, simpler approach: just add token fields to the existing models and create views for token-based response.

**For Observation** (`apps/observations/models.py`):
- Add `response_token` field (CharField, unique, nullable)
- Add `response_token_used` (BooleanField, default=False)
- Add `response_token_sent_at` (DateTimeField, nullable)

**For Inquiry** (`apps/complaints/models.py`):
- Add same fields to Inquiry model

#### b) Create token-based response views
- `observation_respond_with_token(request, pk, token)` — public view, no auth required
- `inquiry_respond_with_token(request, pk, token)` — public view, no auth required

#### c) Update "Send to Department" views
- Generate token, include in email link
- Email template similar to complaint's explanation request

#### d) Update department detail page
- Remove direct response forms (or keep as fallback for logged-in users)
- Show token-based response status instead

---

## 2. ADD REPORTER NOTIFICATIONS

### Current State
- **Complaint**: No notification to complainant when department responds
- **Observation**: SMS + email to reporter when department responds ✓
- **Inquiry**: No notification to inquirer when department responds

### Changes Needed

#### a) Complaint — notify complainant on department response
**File**: `apps/complaints/ui_views.py` (in `involved_department_response` view)
- After department submits response, send SMS + email to complainant
- Include tracking link

#### b) Inquiry — notify inquirer on department response  
**File**: `apps/complaints/ui_views.py` (in `inquiry_department_response` view)
- After department submits response, send SMS + email to inquirer
- Include tracking link

---

## Implementation Order

1. Add token fields to Observation and Inquiry models
2. Create token-based response views for both
3. Update "Send to Department" to generate tokens and send email links
4. Add reporter notifications to complaint and inquiry department response flows
5. Update templates
6. Create migration
