# UpdateValuationPolicy

## Permission Scope

inventoryMaster

## Overview

updateValuationPolicy updates an existing valuation policy. When the standardCostRate is changed for a STANDARD_COST policy, a revaluation flag is set on the response (`revaluationEvent: boolean`) for callers to act on, rather than emitting an event directly.

## Business Rules

- Valuation policy must exist
- standardCostRate is required if costingMethod is STANDARD_COST
- Updating the standard cost rate sets `revaluationEvent: true` in the response; callers are responsible for acting on this flag to trigger downstream recalculation

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B{Policy exists?}
    B -->|No| C[Return error: VALUATION_POLICY_NOT_FOUND]
    B -->|Yes| D{costingMethod is STANDARD_COST?}
    D -->|Yes| E{standardCostRate provided?}
    E -->|No| F[Return error: STANDARD_COST_RATE_REQUIRED]
    E -->|Yes| G[Update policy]
    D -->|No| G
    G --> H{Standard cost rate changed?}
    H -->|Yes| I[Set revaluation flag]
    I --> J[Return updated policy]
    H -->|No| J
```

## External Dependencies

- None

## Error Scenarios

- **VALUATION_POLICY_NOT_FOUND**: Referenced valuation policy does not exist
- **STANDARD_COST_RATE_REQUIRED**: costingMethod is STANDARD_COST but no standardCostRate was provided

## Test Cases

- returns error when not found
- returns error when standard cost rate required
- updates policy name
- updates standard cost rate and emits revaluation event
