# DeleteAccount

## Overview

deleteAccount permanently removes a GL account that is in DRAFT status and has no posted transactions. Accounts in ACTIVE or INACTIVE status cannot be deleted — they must be deactivated instead. Accounts with posted transactions cannot be deleted regardless of status, preserving ledger integrity.

## Business Rules

- Target account must exist
- Parent CoA must be in DRAFT or ACTIVE status; deleting an account under an ARCHIVED CoA is rejected
- Target account must be in DRAFT status
- Target account must have no posted transactions
- Deleting ACTIVE or INACTIVE accounts is rejected

## Process Flow

```mermaid
flowchart TD
    A[Receive delete request] --> B{Account exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| B2{Parent CoA is DRAFT or ACTIVE?}
    B2 -->|No| B3[Return error: CoA is ARCHIVED]
    B2 -->|Yes| D{Status is DRAFT?}
    D -->|No| E[Return error: only DRAFT can be deleted]
    D -->|Yes| F{Has posted transactions?}
    F -->|Yes| G[Return error: has posted transactions]
    F -->|No| H[Delete account record]
    H --> I[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNT_NOT_FOUND**: Specified account ID does not exist
- **CHART_OF_ACCOUNTS_ARCHIVED**: Parent CoA is in ARCHIVED status; no modifications are permitted
- **INVALID_STATE_TRANSITION**: Entity is not in the required status for the requested state transition
- **HAS_POSTED_TRANSACTIONS**: Account has posted transactions and cannot be deleted

## Test Cases

- returns error when account does not exist
- returns error when parent CoA is ARCHIVED
- returns error when account is ACTIVE
- returns error when account is INACTIVE
- returns error when DRAFT account has posted transactions
- deletes a DRAFT account with no posted transactions
