# UpdateWorker

## Permission Scope

`worker`

## Overview

UpdateWorker corrects mutable personal attributes — worker code — on an existing Worker in place, without affecting employment or assignment history.

## Business Rules

- Personal attributes on Worker are period-invariant; update corrects the record in place rather than creating a new generation
- `workerCode` must remain unique across Workers if changed
- A Worker is never hard-deleted or replaced by this command; WorkerEmployment and Assignment history are untouched
- Host-defined custom fields on the Worker model are updated in place alongside the builtin `workerCode`; a builtin column provided in the input always wins over a custom field of the same name

## Process Flow

```mermaid
flowchart TD
    A[Update Worker: workerCode] --> B{Worker exists?}
    B -- No --> X[Reject: WORKER_NOT_FOUND]
    B -- Yes --> C{workerCode changed and unique?}
    C -- No --> Y[Reject: WORKER_CODE_TAKEN]
    C -- Yes --> D[Apply attribute changes in place]
```

## External Dependencies

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

## Error Scenarios

- **WORKER_NOT_FOUND**: the specified Worker does not exist
- **WORKER_CODE_TAKEN**: workerCode is already in use by another Worker

## Test Cases

- updating a Worker's worker code to a new unique value succeeds
- updating a Worker's worker code to one already in use is rejected
- updating a non-existent Worker is rejected
- host-defined custom fields are updated in place alongside the builtin columns

