# UpdateNotificationChannel

## Permission Scope

channelRegistry

## Overview

updateNotificationChannel mutates the admin-facing fields of an existing NotificationChannel registry row — `displayName` and `capabilities`. The `channelId` is the identity of the row and cannot be changed, the derived `kind` topology is likewise immutable, and `enabled` is owned by the dedicated `activateNotificationChannel` / `deactivateNotificationChannel` commands so the kill-switch path is never co-mingled with cosmetic edits. Capability changes propagate to template rendering on the next dispatch (no rendered Notification rows are mutated retroactively).

## Business Rules

- `channelId` is required to identify the target row
- A NotificationChannel row must exist for the supplied `channelId`
- `displayName` is optional; when supplied, must be non-blank after trimming
- `capabilities` is optional; when supplied, must include `supportsHtmlBody`, `supportsAttachments`, and `supportsRichActions` booleans
- `enabled` is **not** mutable through this command (use activate/deactivate)
- `kind` is **not** mutable — it is derived from `channelId` at registration time and fixed for the lifetime of the row

## Process Flow

```mermaid
flowchart TD
    A[Receive update channel request] --> B{NotificationChannel exists?}
    B -->|No| C[Return CHANNEL_NOT_FOUND]
    B -->|Yes| D{displayName supplied?}
    D -->|Yes| E{displayName non-blank?}
    E -->|No| F[Return MISSING_REQUIRED_FIELD]
    E -->|Yes| G{capabilities supplied?}
    D -->|No| G
    G -->|Yes| H{capabilities object has all required keys?}
    H -->|No| F
    H -->|Yes| I[Update channel row with supplied fields]
    G -->|No| I
    I --> J[Return updated channel row]
```

## External Dependencies

- None (operates on module-owned NotificationChannel registry only)

## Error Scenarios

- **CHANNEL_NOT_FOUND**: No NotificationChannel row matches the supplied channelId
- **MISSING_REQUIRED_FIELD**: One or more required input fields are missing or blank

## Test Cases

- updates the displayName on an existing NotificationChannel row
- updates the capabilities object on an existing NotificationChannel row
- leaves enabled unchanged when only displayName / capabilities are supplied
- leaves kind unchanged regardless of which fields are supplied
- returns CHANNEL_NOT_FOUND when the channelId does not exist
- returns MISSING_REQUIRED_FIELD when the supplied displayName is blank
- returns MISSING_REQUIRED_FIELD when the supplied capabilities object is missing supportsHtmlBody
- subsequent dispatches read the new capabilities and already-persisted Notifications are not mutated
