# DeactivateChartOfAccounts

## Permission Scope

chartOfAccounts

## Overview

deactivateChartOfAccounts transitions a Chart of Accounts from ACTIVE to ARCHIVED status. Archiving permanently retires the CoA while preserving the historical account structure for audit and restatement purposes. This is a one-way transition — ARCHIVED CoA records cannot be reactivated. The command name follows the canonical verb convention (`deactivate` instead of `archive`); the target status is ARCHIVED.

## Business Rules

- Target CoA must exist
- Target CoA must be in ACTIVE status
- Deactivating a DRAFT or already ARCHIVED CoA fails with an invalid state transition error
- Archived CoA records and their accounts remain queryable for reporting and audit
- This is a one-way transition; reactivation from ARCHIVED is not permitted

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> B{CoA exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| D{Status is ACTIVE?}
    D -->|No| E[Return error: invalid state transition]
    D -->|Yes| F[Update status to ARCHIVED]
    F --> G[Return archived CoA]
```

## External Dependencies

- None

## Error Scenarios

- **CHART_OF_ACCOUNTS_NOT_FOUND**: Referenced CoA does not exist
- **INVALID_STATE_TRANSITION**: Requested state transition is not allowed from the current status

## Test Cases

- returns error when CoA does not exist
- returns error when CoA is DRAFT
- returns error when CoA is already ARCHIVED
- archives an ACTIVE CoA
