# DeleteChartOfAccounts

## Overview

deleteChartOfAccounts permanently removes a Chart of Accounts that is still in DRAFT status. Only DRAFT CoA records can be deleted. ACTIVE and ARCHIVED records are preserved for operational and audit purposes.

## Business Rules

- Target CoA must exist
- Target CoA must be in DRAFT status; deleting ACTIVE or ARCHIVED CoA is rejected
- Deletion cascade-deletes all child Account and AccountGroup records belonging to the CoA. Because only DRAFT CoA records can be deleted, and accounts can only be created under a DRAFT or ACTIVE CoA, all child accounts are guaranteed to be in DRAFT status with no posted transactions at this point — making cascade deletion safe and consistent with the account deletion invariant

## Process Flow

```mermaid
flowchart TD
    A[Receive delete request] --> B{CoA exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| D{Status is DRAFT?}
    D -->|No| E[Return error: only DRAFT can be deleted]
    D -->|Yes| F[Cascade-delete all child Accounts]
    F --> G[Cascade-delete all child AccountGroups]
    G --> H[Delete CoA record]
    H --> I[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **CHART_OF_ACCOUNTS_NOT_FOUND**: Specified CoA ID does not exist
- **INVALID_STATE_TRANSITION**: Entity is not in the required status for the requested state transition

## Test Cases

- returns error when CoA does not exist
- returns error when CoA is ACTIVE
- returns error when CoA is ARCHIVED
- deletes a DRAFT CoA with no child records
- deletes a DRAFT CoA and cascade-deletes all child Accounts
- deletes a DRAFT CoA and cascade-deletes all child AccountGroups
