# CreateWorkCenter

## Permission Scope

manufacturingMaster

## Overview

CreateWorkCenter creates a draft work center with scope, capacity assumptions, labor or machine rate context, and optional overhead-absorption policy. The work center remains non-executable until explicitly activated.

## Business Rules

- Company scope and unique work-center code are required.
- Site scope is required when the company model uses site-level work centers.
- Capacity must be positive.
- Labor and machine rates must be zero or greater.
- Overhead method, when provided, must be supported by the manufacturing-cost policy.
- New work centers are created in `DRAFT`.

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B[Validate scope and code]
    B --> C[Validate capacity and rates]
    C --> D{Code unique in scope?}
    D -->|No| E[Return DUPLICATE_WORK_CENTER_CODE]
    D -->|Yes| F[Create draft work center]
    F --> G[Return draft work center]
```

## External Dependencies

- [Company](../../../organization/docs/models/Company.md) - Work center scope must belong to a valid company.
- [Site](../../../organization/docs/models/Site.md) - Site-scoped work centers must reference a valid organization site.

## Error Scenarios

- **INVALID_SCOPE**: Required company or site scope is missing.
- **DUPLICATE_WORK_CENTER_CODE**: Another work center already uses the same code in scope.
- **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

- creates a draft work center with positive capacity
- returns error when scope is missing
- returns error when the code already exists in scope
- returns error when capacity is not positive
- returns error when a rate is negative
- returns error when overhead method is invalid
- returns error when fixed-amount overhead omits currency
- creates a draft work center without siteId when not required
