# UpdateWorkCenter

## Overview

UpdateWorkCenter revises mutable work-center master data such as capacity, calendar, rate assumptions, and overhead policy. The target work center can be looked up by `id` or by `companyId` + `siteId` + `code`. The command keeps existing production-order cost snapshots immutable even when active master data changes.

## Business Rules

- Target work center must exist (looked up by `id` or `companyId` + `siteId` + `code`).
- Draft and active work centers may be updated.
- Scope identity and unique code are fixed by the existing record and are used only for lookup.
- Capacity must remain positive.
- Labor and machine rates must be zero or greater.
- Fixed-amount overhead requires a currency.
- Updates do not retroactively change released production-order baselines.

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B{Work center exists?}
    B -->|No| C[Return WORK_CENTER_NOT_FOUND]
    B -->|Yes| D[Validate mutable fields]
    D --> E[Persist work center changes]
    E --> F[Return updated work center]
```

## External Dependencies

- None

## Error Scenarios

- **WORK_CENTER_NOT_FOUND**: Target work center does not exist.
- **INVALID_CAPACITY**: Capacity is zero or negative.
- **INVALID_RATE**: Labor or machine rate is negative.
- **INVALID_OVERHEAD_METHOD**: Overhead method is not supported.
- **OVERHEAD_CURRENCY_REQUIRED**: Fixed-amount overhead requires a currency.

## Test Cases

- updates an active work center without changing scope identity
- returns error when the work center does not exist
- looks up a work center by companyId, siteId, and code
- returns error when capacity is not positive
- returns error when a rate is negative
- preserves released cost baselines after update
- returns error when the overhead method is not supported
- returns error when fixed-amount overhead omits currency
