# DeactivateBillOfMaterial

## Permission Scope

manufacturingMaster

## Overview

DeactivateBillOfMaterial removes an active BOM version from future selection. The command preserves audit history and any released production-order snapshots that already depend on the version.

## Business Rules

- Target BOM must exist.
- Only `ACTIVE` BOM versions can be deactivated.
- Deactivation prevents future production-order release from selecting the version.
- Existing production-order snapshots remain valid after deactivation.
- Deactivation may be blocked when policy requires a replacement active version first.

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> B{BOM exists?}
    B -->|No| C[Return BOM_NOT_FOUND]
    B -->|Yes| D{Status is ACTIVE?}
    D -->|No| E[Return BOM_NOT_DEACTIVATABLE]
    D -->|Yes| F{Replacement policy satisfied?}
    F -->|No| G[Return REPLACEMENT_REQUIRED]
    F -->|Yes| H[Set status to INACTIVE]
    H --> I[Return inactive BOM]
```

## External Dependencies

- None

## Error Scenarios

- **BOM_NOT_FOUND**: Referenced BOM does not exist
- **BOM_NOT_DEACTIVATABLE**: The BOM is not in `ACTIVE`.
- **REPLACEMENT_REQUIRED**: Policy requires another selectable BOM or routing before deactivation

## Test Cases

- deactivates an active BOM
- returns error when the BOM does not exist
- returns error when the BOM is not active
- returns error when replacement policy blocks deactivation
- preserves released production-order snapshots after deactivation
