# ListUnassignedAccounts

## Overview

ListUnassignedAccounts retrieves all active accounts within a Chart of Accounts that are not assigned to any account group. This enables downstream consumers (e.g., reporting module) to validate hierarchy completeness according to their own requirements.

## Business Rules

- chartOfAccountsId is required — accounts are always scoped to a CoA
- Returns only accounts where accountGroupId is null
- Returns only ACTIVE accounts (DRAFT and INACTIVE accounts are excluded as they are not yet or no longer operationally relevant for hierarchy completeness checks)
- Returns full account records (same shape as GetAccount output)
- Results are sorted by account code ascending
- Returns an empty list if all active accounts are assigned to groups

## Process Flow

```mermaid
flowchart TD
    A[Receive input with chartOfAccountsId] --> B[SELECT accounts where chartOfAccountsId = input AND accountGroupId IS NULL AND status = ACTIVE]
    B --> C[Sort by account code ascending]
    C --> D[Return unassigned account list]
```

## External Dependencies

- None

## Error Scenarios

- **EMPTY_RESULT**: No records match the given criteria

## Test Cases

- returns unassigned active accounts in a CoA
- excludes accounts that are assigned to a group
- excludes DRAFT accounts
- excludes INACTIVE accounts
- returns accounts sorted by code ascending
- returns empty list when all active accounts are assigned
