# Realtime Notifications (User Flutter)

Broadcast events (via Laravel Reverb / Pusher-compatible protocol):

- Channel (private): `private-user.{userId}`
- Private-channel auth:
  - endpoint: `POST /broadcasting/auth`
  - header: `Authorization: Bearer <SANCTUM_TOKEN>`

---

## Events to listen

- `notification.created`
  - Payload fields: `id`, `type`, `type_label`, `title`, `body`, `icon_url`, `data`, `is_read`, `read_at`, `created_at`
- `notification.read`
  - Payload fields: `notification_id`, `notification_ids`, `all`, `read_at`

---

## Reverb connection (host/port/scheme)

Use the same values as backend Reverb client config:

- `REVERB_APP_KEY`
- `REVERB_HOST`
- `REVERB_SCHEME` (`http` or `https`)
- `REVERB_PORT`
  - Default backend `REVERB_PORT` is `443`
  - If `REVERB_SCHEME=http`, you typically set WebSocket port to `8080`

The server itself listens on `REVERB_SERVER_PORT` (default `8080`) when running Reverb locally.

---

## Subscribing

Subscribe to the *Pusher channel name*:

- User: `private-user.{userId}`

Note: your Sanctum token must belong to `{userId}` (channel auth enforces it).

Then bind to:

- `notification.created`
- `notification.read`

---

## Mark notifications as read (optional, REST)

Endpoints:

- Unread count: `GET /api/me/notifications/unread-count`
- Mark single: `PATCH /api/me/notifications/{notification}/read`
- Mark all: `PATCH /api/me/notifications/read-all`

