# Command Group 6: Locations

Manage emergency locations for phone number assignments.

**⚠️ Important: All location commands read from PowerShell CSV export**

Microsoft Graph API does **not provide endpoints** for emergency location management. All location operations (`list`, `show`, `search`) read from `~/.teams-phone/cache/locations.csv` generated by the PowerShell export script.

**Graph API Limitation:** The `numberAssignment` resource contains `locationId` and `civicAddressId` fields, but there is no corresponding Graph API to query location details. Emergency locations can only be managed via:
- Teams Admin Center (web UI)
- PowerShell cmdlets: `Get-CsOnlineLisCivicAddress`, `Get-CsOnlineLisLocation`

**Setup Required:** Run `Export-TeamsPhoneData.ps1` to generate location cache. See "Architecture: Hybrid Graph API + CSV Export" section above.

### `locations list`

List all emergency locations in the tenant.

```
teams-phone locations list [OPTIONS]
```

**Data Source:** Reads from `~/.teams-phone/cache/locations.csv`

**Options:**
| Option | Description |
|--------|-------------|
| `--city <city>` | Filter by city |
| `--validated` | Show only validated addresses |
| `--limit <n>` | Limit results (default: 100) |
| `--all` | Fetch all locations |

**Validation:**
- If both `--limit` and `--all` are provided → error: "Cannot specify both --limit and --all"

**Output Fields:**
- Location ID (UUID)
- Name/Description
- Address (street, city, state, postal, country)
- Company Name
- Validation Status (based on export data)
- Default Location (Yes/No)
- Assigned Numbers Count (if available in export)

**Example:**
```bash
# List all emergency locations
teams-phone locations list

# List locations in Seattle
teams-phone locations list --city Seattle

# Output as JSON
teams-phone locations list --json
```

---

### `locations show <location>`

Show detailed information for a specific emergency location.

```
teams-phone locations show <location> [OPTIONS]
```

**Data Source:** Reads from `~/.teams-phone/cache/locations.csv`

**Arguments:**
| Argument | Description |
|----------|-------------|
| `<location>` | Location identifier: ID (UUID), name, or partial match |

**Resolution Behavior:**
- Location ID (UUID format): Exact match required
- Location name: Partial match; if multiple matches found, error with candidate list

**Output Sections:**
1. **Identity**: Location ID (UUID), Name/Description, Civic Address ID
2. **Company**: Company Name
3. **Address**: Street Number, Street Name, City, State/Province, Postal Code, Country
4. **Coordinates**: Latitude/Longitude (if available in export)
5. **Default Status**: Whether this is the default location for the civic address
6. **Export Info**: Last exported timestamp

**Example:**
```bash
# Show location by name
teams-phone locations show "Seattle-HQ"

# Show location by ID
teams-phone locations show loc_abc123

# Show with verbose details
teams-phone locations show "Seattle-HQ" --verbose
```

---

### `locations search <query>`

Search emergency locations by name or address.

```
teams-phone locations search <query> [OPTIONS]
```

**Data Source:** Reads from `~/.teams-phone/cache/locations.csv`

**Arguments:**
| Argument | Description |
|----------|-------------|
| `<query>` | Search term (partial match supported, case-insensitive) |

**Options:**
| Option | Description |
|--------|-------------|
| `--field <field>` | Limit search to: `name`, `address`, `city`, `company` |
| `--limit <n>` | Maximum results (default: 25) |

**Search Behavior:**
- Searches across name/description, full address, city, and company name
- Case-insensitive partial matching
- With `--field`: limits search to specific field only

**Example:**
```bash
# Search by name
teams-phone locations search "HQ"

# Search by city
teams-phone locations search "Seattle" --field city

# Search by street address
teams-phone locations search "Main St" --field address
```

---

