# Channel

## Description

Channel defines an external sell-side context such as a marketplace, storefront, or distributor feed. It scopes listing governance, channel-order synchronization, and channel-specific pricing or identifier behavior without embedding external API mechanics into every sales record.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createChannel
    Draft --> Active: activateChannel
    Active --> Inactive: deactivateChannel
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| activate | DRAFT | ACTIVE | [activateChannel](../commands/ActivateChannel.md) |
| deactivate | ACTIVE | INACTIVE | [deactivateChannel](../commands/DeactivateChannel.md) |

### Command Definitions

- [createChannel](../commands/CreateChannel.md) - Create a draft channel for one company and integration type.
- [updateChannel](../commands/UpdateChannel.md) - Revise mutable channel metadata before or after activation under policy.
- [activateChannel](../commands/ActivateChannel.md) - Make the channel available for listings and sync jobs.
- [deactivateChannel](../commands/DeactivateChannel.md) - Stop future listing activation or new sync intake for the channel.

### Query Definitions

- [getChannel](../queries/GetChannel.md) - Retrieve one sales channel with company scope and status.
- [listChannels](../queries/ListChannels.md) - List channels for commerce administration and support.

### Models

- Channel

### Invariants

- Every channel belongs to exactly one company.
- Only ACTIVE channels may accept newly activated listings or newly started sync jobs unless a recovery policy explicitly allows otherwise.
- Deactivating a channel preserves historical listing and channel-order references.

### Relationships

- **References Company (cross-module)**: `companyId` isolates channel operations by legal entity.
- **Referenced By Listing**: Listings are defined within a specific channel context.
- **Referenced By ChannelOrder and SyncJob**: Channel-originated order ingestion and sync execution are both scoped to one channel.
