# المحادثة (Chat) — نص ومرفقات فقط

كل المسارات هنا محمية (`Authorization: Bearer {token}`). Controller:
`App\Http\Controllers\Api\V1\Clinic\ChatController`، باستخدام `App\Services\Clinic\ChatService`
الموجودة أصلًا (بث حي عبر Reverb + إشعار احتياطي، بغض النظر عن حالة الاتصال).

**خارج النطاق تمامًا:** لا يوجد مكالمة فيديو من أي نوع — المحادثة نص/مرفق فقط، ولا يوجد
تخطيط لإضافة فيديو في هذه المرحلة.

## GET v1/chat/doctors/{doctor}/messages?page=

كل رسائل المحادثة بين المريض والدكتور، بالترتيب الزمني. الطلب ده بيعلّم رسائل الدكتور
كمقروءة تلقائيًا (`read_at`). لو الدكتور `status != active` → `404`.

```json
{
  "success": true, "code": "OK", "message": "تمت العملية بنجاح",
  "data": [
    {
      "id": 1, "sender_type": "patient",
      "body": "Doctor, is it okay to take the medicine on an empty stomach?",
      "attachment_url": null, "attachment_type": null,
      "read_at": "2026-08-26T15:22:26+03:00", "created_at": "2026-09-04T15:22:26+03:00"
    },
    {
      "id": 2, "sender_type": "doctor",
      "body": "Better to take it after a meal to avoid stomach irritation.",
      "attachment_url": null, "attachment_type": null,
      "read_at": "2026-08-26T15:22:26+03:00", "created_at": "2026-09-04T15:22:26+03:00"
    }
  ],
  "meta": {}, "errors": null
}
```

## POST v1/chat/doctors/{doctor}/messages (multipart/form-data لو فيه مرفق)

| الحقل | القواعد |
|---|---|
| `body` | مطلوب لو مفيش `attachment`، نص، أقصى 5000 حرف |
| `attachment` | اختياري، ملف، أقصى 10MB، الأنواع: `jpg,jpeg,png,webp,pdf,doc,docx` |

```json
{
  "success": true, "code": "CREATED", "message": "تم الإنشاء بنجاح",
  "data": {
    "id": 3, "sender_type": "patient",
    "body": "Hello doctor, quick question about my meds",
    "attachment_url": null, "attachment_type": null,
    "read_at": null, "created_at": "2026-09-11T00:57:24+03:00"
  },
  "meta": {}, "errors": null
}
```

## GET v1/chat/unread-count

عدد رسائل الدكاترة غير المقروءة عبر كل المحادثات — لاستخدامه في شارة (badge) الشاشة
الرئيسية/التابات.

```json
{
  "success": true, "code": "OK", "message": "تمت العملية بنجاح",
  "data": { "count": 2 }, "meta": {}, "errors": null
}
```

**ملاحظة موجودة من قبل (مش جديدة):** أي مريض مسجّل دخوله يقدر يبعت رسالة لأي دكتور نشط —
مفيش شرط "لازم يكون له حجز مع الدكتور ده" حاليًا، سواء في الموبايل أو الموقع.
