# ReviewManufacturingCostSummary

## Permission Scope

productionOrder

## Overview

ReviewManufacturingCostSummary recalculates the final planned-versus-actual result for a technically complete order and freezes the variance classification through an explicit reviewer approval step.

## Business Rules

- Target cost summary must exist and be in `PENDING_VARIANCE_REVIEW`.
- Parent production order must already be `TECHNICALLY_COMPLETE`.
- Final variance must be recalculated against the frozen release baseline.
- Review must preserve the named variance taxonomy: `MATERIAL_PRICE`, `MATERIAL_USAGE`, `LABOR_RATE`, `LABOR_EFFICIENCY`, `MACHINE_RATE`, `MACHINE_EFFICIENCY`, `SCRAP`, and `YIELD`.
- Reviewer identity is required.
- Approved review freezes the variance breakdown until the order is reopened.

## Process Flow

```mermaid
flowchart TD
    A[Receive review request] --> B{Summary exists and is pending review?}
    B -->|No| C[Return COST_SUMMARY_NOT_REVIEWABLE]
    B -->|Yes| D[Recalculate final variances across the named taxonomy]
    D --> E{All required categories supported?}
    E -->|No| F[Return INCOMPLETE_VARIANCE_BREAKDOWN]
    E -->|Yes| G{Reviewer provided?}
    G -->|No| H[Return REVIEWER_REQUIRED]
    G -->|Yes| I[Freeze variance lines and set VARIANCE_REVIEWED]
    I --> J[Return reviewed summary]
```

## External Dependencies

- [ProductionOrder](../model/ProductionOrder.md) - Parent order must already be technically complete before review.

## Error Scenarios

- **COST_SUMMARY_NOT_FOUND**: Referenced cost summary does not exist
- **COST_SUMMARY_NOT_REVIEWABLE**: Summary is not in `PENDING_VARIANCE_REVIEW`.
- **PARENT_ORDER_NOT_TECHNICALLY_COMPLETE**: Parent production order is not ready for review.
- **INCOMPLETE_VARIANCE_BREAKDOWN**: The review result cannot represent the full named variance taxonomy required by the feature.
- **REVIEWER_REQUIRED**: Reviewer identity was not provided.
- **VARIANCE_CALCULATION_FAILED**: Final variance could not be recalculated consistently.

## Test Cases

- reviews a pending cost summary and freezes the variance breakdown
- returns error when the summary does not exist
- returns error when the summary is not pending review
- returns error when the parent order is not technically complete
- returns error when the review result cannot represent all required variance types
- returns error when reviewer identity is missing
- keeps all required variance types distinct during review
- returns error when final variance cannot be recalculated consistently
