# Phase 6 — Booking-aware Chat Inbox

This build is based on the Phase 5 Product Discovery package. It replaces the earlier expectation of finding chat only from booking details with a dashboard inbox for each role.

## Behaviour
- Customer opens **My Chats** from the top navigation or customer dashboard. It lists each accepted booking as its own conversation and identifies the provider, service, business and booking reference.
- Provider opens **Booking Chats** from the top navigation or provider dashboard. It lists each accepted booking and the corresponding customer.
- A conversation is automatically created in the same transaction when the provider accepts a booking. The inbox also synchronizes eligible existing bookings so accepted bookings created before this migration appear.
- One conversation per booking. Booking identity is never accepted from a form alone; every thread lookup checks that the signed-in user is that booking's customer or provider.
- Rejected, cancelled and expired bookings close the conversation. Completed bookings remain open for 24 hours, after which inbox synchronization closes them.
- Text messages, timestamps, unread counts, in-app notification, report submission and basic phone/email/link filtering are included.

## Install
1. Back up the project and database.
2. Merge this package over your Phase 5 installation, preserving `.env`, uploaded files, private storage and keys.
3. Run `C:\xampp\php\php.exe bin\migrate.php` from `C:\xampp\htdocs\bizmtaani`. Migration `007_booking_chat_inbox.sql` creates the chat tables.
4. Sign in as a customer and open **My Chats**, or sign in as a provider and open **Booking Chats**.
5. For an existing confirmed booking, opening the inbox creates its conversation automatically. New conversations are created automatically when a provider accepts a booking.

## Test
- Customer A cannot open a conversation belonging to Customer B.
- Provider A cannot open a conversation belonging to Provider B.
- Confirm a booking as provider and verify it appears on both dashboards.
- Send messages in both directions and verify unread counts / notifications.
- Try Kenyan mobile formats such as 0712345678, 0112345678 and +254 712 345 678; the attempted message must not be stored.
- Try ordinary messages mentioning prices, quantities and appointment dates; they should be accepted.
- Cancel or reject a booking and verify chat becomes read-only.

## Limitations
The phone-number filter is heuristic, not foolproof. This phase does not provide live WebSocket messaging; users refresh/reopen the thread to see new messages. Email message notifications are not enabled here; in-app notifications are used. Moderation reports are recorded but a full staff moderation screen and audited message-retention purge job are future work. Configure HTTPS for production.
