# DeactivateCurrency

## Permission Scope

currency

## Overview

DeactivateCurrency disables a currency from being used in new transactions while preserving all historical data. This command supports scenarios such as market exit or currency obsolescence (e.g., legacy national currencies replaced by EUR). Deactivated currencies remain in the system for reporting and audit purposes.

## Business Rules

- Target currency must exist in the system
- Target currency must be in Active status
- Base currency cannot be deactivated - must first change base currency to another active currency
- Deactivating an already inactive currency returns success with no state change
- Historical transactions using this currency are not affected
- Deactivation prevents the currency from being used in new transactions, exchange rates, or price lists

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> B{Currency exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| D{Is base currency?}
    D -->|Yes| E[Return error: cannot deactivate base currency]
    D -->|No| F{Current status?}
    F -->|Inactive| G[Return success: already inactive]
    F -->|Active| H[Update status to Inactive]
    H --> I[Return deactivated currency]
```

## External Dependencies

- None

## Error Scenarios

- **CURRENCY_NOT_FOUND**: Referenced currency does not exist
- **CANNOT_DEACTIVATE_BASE_CURRENCY**: Attempting to deactivate the base currency, must change base currency first

## Test Cases

- throws when currency doesn't exist
- throws when attempting to deactivate base currency
- returns currency unchanged when already inactive
- deactivates active non-base currency
