# UpdateRouting

## Overview

UpdateRouting revises mutable draft routing content before activation. It supports operation resequencing, instruction changes, and work-center reassignment while preserving snapshots already frozen on released production orders.

## Business Rules

- Target routing must exist.
- Only `DRAFT` routings are mutable through this command.
- Revised operation sequence numbers must remain unique.
- Revised standard times must be zero or greater.
- Every referenced work center must exist in the same company scope.
- Updating a routing never mutates operation snapshots already copied onto released work orders.

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B{Routing exists?}
    B -->|No| C[Return ROUTING_NOT_FOUND]
    B -->|Yes| D{Status is DRAFT?}
    D -->|No| E[Return ROUTING_NOT_MUTABLE]
    D -->|Yes| F[Validate revised operations]
    F --> G[Persist draft changes]
    G --> H[Return updated routing]
```

## External Dependencies

- [Item](../../../item-management/docs/models/Item.md) - The routing remains scoped to one manufactured parent item.
- [WorkCenter](../models/WorkCenter.md) - Revised operations must continue to reference valid work centers.

## Error Scenarios

- **ROUTING_NOT_FOUND**: Target routing does not exist.
- **ROUTING_NOT_MUTABLE**: The routing is not in `DRAFT`.
- **DUPLICATE_OPERATION_SEQUENCE**: Two operations use the same sequence number.
- **INVALID_STANDARD_TIME**: Setup or run time is negative.
- **WORK_CENTER_NOT_FOUND**: A referenced work center does not exist.
- **CROSS_COMPANY_WORK_CENTER**: A work center belongs to a different company scope.

## Test Cases

- updates draft routing operations
- returns error when the routing does not exist
- returns error when the routing is not in DRAFT
- returns error when revised sequence numbers conflict
- returns error when a revised standard time is negative
- returns error when a referenced work center does not exist
- returns error when a referenced work center is outside the routing company
- preserves released routing snapshots after update
