# UpdatePartnerBankAccount

## Permission Scope

partnerDetail

## Overview

updatePartnerBankAccount modifies bank details through the owning BusinessPartner aggregate. All fields are optional, but the same validation rules that apply at creation are enforced for any provided values. This allows incremental updates to banking information as details change. Updates are permitted whether the parent partner is active or inactive.

## Business Rules

- Bank account must exist in the system
- The owning BusinessPartner aggregate is loaded with a row lock before bank details are changed
- Updates are permitted whether the partner has `status=ACTIVE` or `status=INACTIVE`
- Bank name, if provided, must be non-empty
- Account holder name, if provided, must be non-empty
- After update, accountNumber must remain non-empty
- `routingNumber` is optional — can be added, updated, or cleared
- Currency, if provided, must reference an existing Currency in the primitives module

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B[Lock and load owning BusinessPartner aggregate]
    B --> C{Bank account exists?}
    C -->|No| D[Return error: bank account not found]
    C -->|Yes| E{Changed currency exists?}
    E -->|No| F[Return error: currency not found]
    E -->|Yes or unchanged| G[Merge provided bank details]
    G --> H{Bank name, holder and account number non-empty?}
    H -->|No| I[Return validation error]
    H -->|Yes| J[Save aggregate and return bank account ID]
```

## External Dependencies

- [primitives::Currency](../../../primitives/docs/model/Currency.md) - Validates that the referenced currency exists (when provided)

## Error Scenarios

- **BANK_ACCOUNT_NOT_FOUND**: Specified bank account ID does not exist
- **INVALID_BANK_NAME**: Bank name is empty, whitespace-only, or not provided
- **INVALID_ACCOUNT_HOLDER_NAME**: Account holder name is empty, whitespace-only, or not provided
- **CURRENCY_NOT_FOUND**: Referenced currency does not exist
- **MISSING_ACCOUNT_IDENTIFIER**: Account number is empty or not provided

## Test Cases

- updates bank details through the BusinessPartner aggregate
- allows correction while the partner is inactive
- returns error when the bank account does not exist
- returns error when the new currency does not exist

The parameterized `rejects invalid bank details %#` test covers empty bank names, empty account holder names, and empty or whitespace-only account numbers.
