# Workflow — RM-Led Booking

End-to-end flow from a client raising an RM request on the public app, through the RM creating an event, to vendors quoting, to closure.

---

## Sequence

```
┌───────────────┐    ┌───────────────┐    ┌──────────────┐    ┌──────────────┐
│ 1. Client     │    │ 2. Request    │    │ 3. RM picks  │    │ 4. RM creates│
│    raises RM  │───▶│    visible in │───▶│    & chats   │───▶│    event on  │
│    request    │    │    /rm-requests│    │    in app    │    │    behalf    │
└───────────────┘    └───────────────┘    └──────────────┘    └──────┬───────┘
                                                                     │
                                                                     ▼
                                                            ┌─────────────────┐
                                                            │ 5. INSERT events│
                                                            │   + event_svcs  │
                                                            │   + UPDATE      │
                                                            │   client_rm_req │
                                                            │   (status=2)    │
                                                            └────────┬────────┘
                                                                     │
                                                                     ▼
                                                            ┌─────────────────┐
                                                            │ 6. Notification │
                                                            │    inapp +      │
                                                            │    socket push  │
                                                            └────────┬────────┘
                                                                     │
                                                                     ▼
                                                            ┌─────────────────┐
                                                            │ 7. Vendors get  │
                                                            │    lead (via    │
                                                            │    OotboAPI     │
                                                            │    matching)    │
                                                            └────────┬────────┘
                                                                     │
                                                                     ▼
                                                            ┌─────────────────┐
                                                            │ 8. Vendor       │
                                                            │    submits quote│
                                                            │    on app       │
                                                            └────────┬────────┘
                                                                     │
                                                                     ▼
                                                            ┌─────────────────┐
                                                            │ 9. RM/client    │
                                                            │    closes loop  │
                                                            │    status=4     │
                                                            └─────────────────┘
```

## Step-by-Step

| # | Step | Feature(s) | Endpoint / Action |
|---|------|------------|------------------|
| 1 | Client raises RM request from the public app | (OotboApps client) | POST to OotboAPI — writes `client_rm_requests` row |
| 2 | RM logs in to VisoAdmin, sees the new request in their country-scoped list | [08 RM Requests](../08-rm-requests/spec.md) | `GET /rm/ajaxGetRmData` |
| 3 | RM opens the request detail; reads client details, chats with client (via app) | [08 RM Requests](../08-rm-requests/spec.md) | `GET /rm/rm-request-details/{uuid}` |
| 4 | RM clicks "Create Event" → fills out the event form (UAE-pinned) | [09 RM Create Event](../09-rm-create-event/spec.md) | `GET /rm/create-event/{uuid}` |
| 5 | RM submits — VisoAdmin writes `events`, `event_services`, updates `client_rm_requests` (status=2) | [09 RM Create Event](../09-rm-create-event/spec.md) | `POST /rm/store-event` |
| 6 | VisoAdmin writes a `notifications` row + POSTs to Viso-Chat socket | [09 RM Create Event](../09-rm-create-event/spec.md) → `Viso-Chat` | `POST <SOCKET_URL>/notification` |
| 7 | OotboAPI's lead-matching pipeline picks up the new event → vendor app dashboards show the lead | (OotboApps vendor) | — |
| 8 | Vendor submits a quote on their app | (OotboApps vendor + OotboAPI) | OotboAPI writes `event_services_vendor_quote` |
| 9 | RM/Coordinator monitors progress in VisoAdmin event details; once vendor hired + paid, `client_rm_requests.status` advances (currently set externally — verify) | [06 Event Oversight](../06-event-oversight/spec.md) + [08 RM Requests](../08-rm-requests/spec.md) | — |

## Touched Tables

`client_rm_requests`, `events`, `event_services`, `event_services_vendor_quote`, `notifications`, `categories`, `countries`, `states`, `cities`, `services`, `users`.

## Failure Modes

- **Step 4 aborts** if UAE is not in the `countries` master.
- **Step 5 rolls back** if any of the 3 INSERT/UPDATE statements fail (DB::beginTransaction).
- **Step 6 fails silently** (try/catch) — event still saved. Client may not get realtime notification.
- **Step 7 depends on OotboAPI matching pipeline** — VisoAdmin doesn't push a lead; it relies on OotboAPI listening to event-created.
