# CreateBankStatement

## Permission Scope

bankStatement

## Overview

createBankStatement atomically imports one bank statement header and its lines.

## Business Rules

- BankAccount must exist and be ACTIVE
- Statement must contain at least one line
- Line numbers are positive and unique
- Line amounts are positive
- Opening balance plus CREDIT amounts minus DEBIT amounts equals closing balance

## Process Flow

```mermaid
flowchart LR
    A[Receive statement] --> B[Validate BankAccount and lines]
    B --> C[Validate closing balance]
    C --> D[Create header and lines atomically]
```

## External Dependencies

- None

## Error Scenarios

- **CASH_BANK_ACCOUNT_NOT_FOUND**: Bank account does not exist
- **CASH_BANK_ACCOUNT_INACTIVE**: Bank account is inactive
- **CASH_BANK_STATEMENT_INVALID**: Lines, numbering, amounts, or balances are invalid

## Test Cases

- creates a balanced statement and its lines
- rejects a statement whose balances do not reconcile to line movements
