# GetAccountGroup

## Overview

GetAccountGroup retrieves a single account group record by id or by code within a CoA. The input is a union type — callers specify exactly one lookup variant. This serves as the core group lookup for existence checks, hierarchy validation, and group management commands.

## Business Rules

- Accepts one of two lookup variants:
  - `{ id }` — retrieves by unique identifier
  - `{ chartOfAccountsId, code }` — retrieves by group code within a specific CoA
- Returns the full group record including all fields (id, chartOfAccountsId, parentAccountGroupId, code, name, sortOrder, rangeStart, rangeEnd, timestamps)
- Returns null if no matching group is found
- All comparisons are exact

## Process Flow

```mermaid
flowchart TD
    A[Receive input] --> B{Which variant?}
    B -->|id| C[SELECT from AccountGroup where id = input.id]
    B -->|chartOfAccountsId + code| D[SELECT from AccountGroup where chartOfAccountsId = input.chartOfAccountsId AND code = input.code]
    C --> E{Group found?}
    D --> E
    E -->|Yes| F[Return group record]
    E -->|No| G[Return null]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNT_GROUP_NOT_FOUND**: Referenced account group does not exist or belongs to a different CoA

## Test Cases

- returns group when found by id
- returns null when group not found by id
- returns group when found by code within CoA
- returns null when group not found by code within CoA
