# DeleteAccountGroup

## Overview

deleteAccountGroup permanently removes an account group that has no child groups and no assigned accounts. Groups with children or assigned accounts must have those relationships resolved before deletion.

## Business Rules

- Target group must exist
- Parent CoA must be in DRAFT or ACTIVE status; deleting a group under an ARCHIVED CoA is rejected
- Group must have no child groups
- Group must have no accounts assigned to it

## Process Flow

```mermaid
flowchart TD
    A[Receive delete request] --> B{Group 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{Has child groups?}
    D -->|Yes| E[Return error: has children]
    D -->|No| F{Has assigned accounts?}
    F -->|Yes| G[Return error: has assigned accounts]
    F -->|No| H[Delete group]
    H --> I[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNT_GROUP_NOT_FOUND**: Specified group ID does not exist
- **CHART_OF_ACCOUNTS_ARCHIVED**: Parent CoA is in ARCHIVED status; no modifications are permitted
- **HAS_CHILD_GROUPS**: Group contains child groups and cannot be deleted
- **HAS_ASSIGNED_ACCOUNTS**: Group has accounts assigned to it and cannot be deleted

## Test Cases

- returns error when group does not exist
- returns error when parent CoA is ARCHIVED
- returns error when group has child groups
- returns error when group has assigned accounts
- deletes a leaf group with no assigned accounts
