# UpdateWorkRegime

## Permission Scope

`workRegime`

## Overview

UpdateWorkRegime corrects an existing WorkRegime catalog entry's `key` or `displayName` in place. It does not change the entry's `companyId` or `status` — status transitions are handled by deactivate/reactivate.

## Business Rules

- The entry is identified by `id`; `key` and `displayName` are optional and only the supplied fields are changed
- A `key` change must remain unique within the entry's company; colliding with another entry in the same company is rejected
- Re-supplying the entry's own current `key` is not treated as a collision
- `companyId` and `status` are never changed by this command

## Process Flow

```mermaid
flowchart TD
    A[Update WorkRegime: id, key?, displayName?] --> B{WorkRegime exists?}
    B -- No --> X[Reject: WORK_REGIME_NOT_FOUND]
    B -- Yes --> C{key changed and unique in company?}
    C -- No --> Y[Reject: DUPLICATE_WORK_REGIME_KEY]
    C -- Yes --> D[Apply key/displayName changes in place]
    D --> E[Referencing WorkerEmployments see updated label]
```

## External Dependencies

- [workforce::WorkRegime](../model/WorkRegime.md) model — the entity this command mutates

## Error Scenarios

- **WORK_REGIME_NOT_FOUND**: no WorkRegime exists for the given id
- **DUPLICATE_WORK_REGIME_KEY**: a work regime with the given key already exists in the company

## Test Cases

- updating a work regime's displayName persists the change in place
- updating a work regime's key to an unused key in the same company succeeds
- updating a non-existent work regime is rejected
- updating a work regime's key to one already used by another entry in the same company is rejected
- re-supplying the entry's own current key is accepted
