# CodeIgniter Integration Examples

## 1) CodeIgniter -> FastAPI AI assess

`POST /gold-theft-detection/ai-assess`

```json
{
  "event_id": "dispatch-2026-0007",
  "site_id": 1,
  "vehicle_id": "T 908 ABK",
  "operator_id": "staff-88",
  "dispatch_weight": 900.0,
  "received_weight": 881.5,
  "expected_duration_minutes": 35,
  "actual_duration_minutes": 56,
  "gps_trace": [[-6.801,39.28],[-6.89,39.41]],
  "face_verified": false,
  "timestamp": "2026-03-26T15:22:00Z"
}
```

Response includes:
- `detect.anomaly_score`, `detect.is_anomaly`
- `predict.theft_risk_probability`, `predict.blocked`

If `blocked=true`, CI stores an alert and marks workflow block status in cache.

## 2) FastAPI -> CodeIgniter callback alert

`POST /api/ai-integration/alerts`

Authorization:
- `Authorization: Bearer <AI_CALLBACK_TOKEN>`

Payload:
```json
{
  "alert_key": "dedupe-key",
  "event_id": "dispatch-2026-0007",
  "severity": "critical",
  "message": "High theft risk detected by AI",
  "evidence": { "probability": 0.92 }
}
```

## 3) FastAPI -> CodeIgniter workflow block callback

`POST /api/ai-integration/workflow-block`

Authorization:
- `Authorization: Bearer <AI_CALLBACK_TOKEN>`

Payload:
```json
{
  "event_id": "dispatch-2026-0007",
  "reason": "AI theft risk threshold exceeded",
  "probability": 0.92
}
```
