# ActivateBillOfMaterial

## Overview

ActivateBillOfMaterial validates a draft BOM version and makes it selectable for production-order release. Activation is where circular-reference checks, effectivity conflicts, and component readiness are enforced.

## Business Rules

- Target BOM must exist and be in `DRAFT`.
- The BOM must contain at least one valid component line.
- All referenced items must be active in the required scope.
- Manufactured-child references must not create a direct or indirect circular structure.
- Overlapping active effectivity windows for the same parent item and scope are rejected unless selection remains unambiguous.
- Activation preserves any already released production-order snapshots from other versions.

## Process Flow

```mermaid
flowchart TD
    A[Receive activate request] --> B{BOM exists and is DRAFT?}
    B -->|No| C[Return BOM_NOT_ACTIVATABLE]
    B -->|Yes| D[Validate component readiness]
    D --> E[Check circular references]
    E --> F[Check effectivity conflicts]
    F --> G[Set status to ACTIVE]
    G --> H[Return active BOM]
```

## External Dependencies

- [detectBillOfMaterialCircularReference](../queries/DetectBillOfMaterialCircularReference.md) - Prevent cyclical manufactured-item structures.

## Error Scenarios

- **BOM_NOT_FOUND**: Target BOM does not exist.
- **BOM_NOT_ACTIVATABLE**: The BOM is not in `DRAFT`.
- **COMPONENT_LINE_REQUIRED**: The BOM has no component lines.
- **COMPONENT_ITEM_INACTIVE**: A referenced component is inactive.
- **CIRCULAR_BOM_REFERENCE**: A direct or indirect manufactured-item loop was detected.
- **EFFECTIVITY_CONFLICT**: Activation would create conflicting active effectivity windows.

## Test Cases

- activates a valid draft BOM
- returns error when the BOM does not exist
- returns error when the BOM is not in `DRAFT`
- returns error when the BOM has no component lines
- returns error when a component item is inactive
- returns error when a circular manufactured-item structure is detected
- returns error when activation would create an effectivity conflict
