# CustomerAccount

## Description

CustomerAccount represents the customer-facing transaction unit for one BusinessPartner in one Company. Multiple account codes may exist for the same partner and company so departments or commercial units can use different currency, address, bank, and other transaction settings.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Active: createCustomerAccount (status=ACTIVE)
    Active --> Inactive: deactivateCustomerAccount
    Inactive --> Active: reactivateCustomerAccount
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| deactivate | ACTIVE | INACTIVE | [deactivateCustomerAccount](../command/DeactivateCustomerAccount.md) |
| reactivate | INACTIVE | ACTIVE | [reactivateCustomerAccount](../command/ReactivateCustomerAccount.md) |

### Command Definitions

- [createCustomerAccount](../command/CreateCustomerAccount.md) - Create an active customer account and its initial usages
- [updateCustomerAccount](../command/UpdateCustomerAccount.md) - Patch mutable account fields and apply line-style usage changes
- [deactivateCustomerAccount](../command/DeactivateCustomerAccount.md) - Stop the account without affecting the global partner
- [reactivateCustomerAccount](../command/ReactivateCustomerAccount.md) - Restore an inactive account for business use

### Query Definitions

- [GetCustomerAccount](../query/GetCustomerAccount.md) - Retrieve an account by id

### Models

- CustomerAccount
- CustomerAddressUsage
- CustomerBankAccountUsage

### Invariants

- Account name is required and must not be empty or whitespace-only

- The partner must be ACTIVE when an account is created
- Account code is required and unique within a company
- Company and preferred currency references must exist
- Address and bank account usages may only reference records owned by the same partner
- At most one default exists per usage purpose within an account
- Accounts are active when created
- CustomerAccount records are deactivated rather than physically deleted
- Only active accounts are available for new customer transactions
- Approval or registration workflow, if required, is modeled separately from CustomerAccount
- Account deactivation is independent from BusinessPartner availability

### Relationships

- **References BusinessPartner**: Identity and globally maintained master data
- **References Company**: Organizational scope of the transaction account
- **References Currency**: Optional preferred transaction currency
- **Referenced By CustomerAddressUsage**: Purpose-specific address configuration
- **Referenced By CustomerBankAccountUsage**: Purpose-specific bank configuration
