# Workspace Inbound Routing + Extension Capture Contract Architecture

## Purpose
This document defines the early inbound phone-system contract for workspace-owned business numbers before live Twilio inbound routing is wired.

## Scope
This architecture covers:
- inbound call contract shape
- extension digit capture contract
- dispatcher extension lookup contract
- busy and offline fallback branch rules
- callback and voicemail continuity contract
- admin-only staging surfaces

## Core rules
1. Workspace-owned numbers belong to the workspace, not to an individual dispatcher.
2. Each enabled dispatcher extension must be unique within the workspace.
3. Inbound call handling must stay predictable before real IVR wiring begins.
4. Busy, offline, voicemail, and callback continuity decisions must be staged in admin settings before live inbound rollout.
5. Operator-facing dialer surfaces must stay separate from admin routing configuration.

## Contract stages
- `PLANNING`: business phone system still being defined
- `CONTRACT_STAGED`: routing rules are staged in admin settings
- `READY_FOR_IVR`: contract is stable enough for live inbound IVR wiring

## Entry modes
- `EXTENSION_CAPTURE`: caller is asked for dispatcher extension first
- `MAIN_MENU_THEN_EXTENSION`: caller hears a short menu first, then enters extension
- `QUEUE_ONLY`: caller goes directly to a queue without extension entry

## Inbound flow contract
1. Workspace number receives the inbound call
2. Entry contract decides whether to gather extension digits or route directly
3. Extension lookup resolves one enabled dispatcher assignment
4. Busy/offline contract chooses fallback path when direct routing is not available
5. Unresolved calls branch into dispatch queue, voicemail, or callback continuity according to staged rules

## Dispatcher lookup rules
- only enabled extension assignments can receive direct extension routing
- extension digits must match the workspace extension length setting
- duplicate extensions are not allowed within the workspace
- unresolved, disabled, or missing extensions must follow the staged unresolved route

## Fallback rules
### Busy dispatcher
Options:
- keep primary dispatcher
- backup dispatcher
- dispatch queue
- voicemail

### Offline dispatcher
Options:
- dispatch queue
- voicemail
- callback task

## Unresolved input rules
### No input
Options:
- repeat prompt
- dispatch queue
- voicemail

### Invalid extension
Options:
- repeat prompt
- dispatch queue
- voicemail

## Continuity rules
### Callback continuity
If enabled, unresolved or unreachable inbound calls should create callback continuity so the workspace can follow up later.

### Voicemail continuity
If enabled, voicemail can become an allowed branch inside the unresolved, busy, or offline routing rules.

## Admin staging surfaces
Current staging surfaces should live under workspace/company admin settings, not inside the dispatcher dialer.

## Not yet included
This version does not yet add:
- live inbound Twilio IVR
- real extension ringing
- live voicemail recording pipeline
- real callback task creation from inbound events
- full inbound queue execution
