# DeactivateCategory

## Permission Scope

category

## Overview

DeactivateCategory disables a UoM category from being used in new product assignments while preserving all historical data and existing product associations. This command supports scenarios such as discontinuing a measurement standard or consolidating categories.

## Business Rules

- Target category must exist in the system
- Target category must be in Active status
- Category with active units cannot be deactivated - all units must be deactivated first
- Deactivating an already inactive category returns success with no state change
- Historical transactions and products using this category's units are not affected
- Deactivation prevents new products from being assigned units in this category

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> B{Category exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| D{Has active units?}
    D -->|Yes| E[Return error: has active units]
    D -->|No| F{Current status?}
    F -->|Inactive| G[Return success: already inactive]
    F -->|Active| H[Update status to Inactive]
    H --> I[Return deactivated category]
```

## External Dependencies

- None

## Error Scenarios

- **UOM_CATEGORY_NOT_FOUND**: Specified UoM category does not exist
- **CATEGORY_HAS_ACTIVE_UNITS**: Category still contains active units that must be deactivated first

## Test Cases

- throws when category doesn't exist
- throws when category has active units
- returns category unchanged when already inactive
- deactivates active category with no active units
