# ListAccountGroups

## Overview

ListAccountGroups retrieves account groups within a Chart of Accounts, optionally filtered by parent group. This supports hierarchical tree traversal by enabling consumers to query root groups (parent = null) or children of a specific parent. Results are sorted by sort order within each sibling set.

## Business Rules

- chartOfAccountsId is required — groups are always scoped to a CoA
- Optional filter:
  - `parentAccountGroupId` — filter by parent group (null for root groups)
- Returns full group records (same shape as GetAccountGroup output)
- Results are sorted by sortOrder ascending within each sibling set
- Returns an empty list if no groups match

## Process Flow

```mermaid
flowchart TD
    A[Receive input with chartOfAccountsId] --> B{Parent filter provided?}
    B -->|Yes| C[SELECT groups where parentAccountGroupId = input.parentAccountGroupId]
    B -->|No| D[SELECT all groups in CoA]
    C --> E[Sort by sortOrder ascending]
    D --> E
    E --> F[Return group list]
```

## External Dependencies

- None

## Error Scenarios

- **EMPTY_RESULT**: No groups match the given criteria — returns empty list

## Test Cases

- returns all groups in a CoA when no parent filter applied
- returns root groups when parent filter is null
- returns child groups of a specific parent
- returns groups sorted by sort order
- returns empty list when no groups match
