# ActivateRouting

## Permission Scope

manufacturingMaster

## Overview

ActivateRouting validates a draft routing and makes it eligible for production-order release. Activation enforces operation completeness, sequence integrity, and active work-center readiness.

## Business Rules

- Target routing must exist and be in `DRAFT`.
- The routing must contain at least one operation.
- Operation sequence numbers must be unique and ordered.
- Every referenced work center must be active and within the same company.
- Activation preserves existing operation snapshots already frozen on released orders.

## Process Flow

```mermaid
flowchart TD
    A[Receive activate request] --> B{Routing exists and is DRAFT?}
    B -->|No| C[Return ROUTING_NOT_ACTIVATABLE]
    B -->|Yes| D[Validate operations]
    D --> E[Validate work-center readiness]
    E --> F[Set status to ACTIVE]
    F --> G[Return active routing]
```

## External Dependencies

- [WorkCenter](../model/WorkCenter.md) - Referenced work centers must already be active.

## Error Scenarios

- **ROUTING_NOT_FOUND**: Referenced routing does not exist
- **ROUTING_NOT_ACTIVATABLE**: The routing is not in `DRAFT`.
- **OPERATION_REQUIRED**: Routing has no operations
- **DUPLICATE_OPERATION_SEQUENCE**: Two operations use the same sequence number.
- **WORK_CENTER_NOT_ACTIVE**: A referenced work center is inactive.
- **CROSS_COMPANY_WORK_CENTER**: A work center belongs to a different company scope.

## Test Cases

- activates a valid draft routing
- returns error when the routing does not exist
- returns error when the routing is not in DRAFT
- returns error when the routing has no operations
- returns error when operation sequence numbers are duplicated
- returns error when a referenced work center is inactive
- returns error when a referenced work center is outside the routing company
