# UpdatePartnerBankAccount

## Permission Scope

partnerDetail

## Overview

updatePartnerBankAccount modifies the details of an existing bank account. 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 regardless of the parent partner's lifecycle status (DRAFT, ACTIVE, or INACTIVE).

## Business Rules

- Bank account must exist in the system
- Parent partner's status is not checked — updates are permitted in any lifecycle state (DRAFT, ACTIVE, or INACTIVE)
- Bank name, if provided, must be non-empty
- Account holder name, if provided, must be non-empty
- After update, at least one of accountNumber or iban must still be present
- `routingNumber` is optional — can be added, updated, or cleared
- `swiftBic` 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{Bank account exists?}
    B -->|No| C[Return error: bank account not found]
    B -->|Yes| D{bankName provided and empty?}
    D -->|Yes| D1[Return error: invalid bank name]
    D -->|No| E2{accountHolderName provided and empty?}
    E2 -->|Yes| E3[Return error: invalid account holder name]
    E2 -->|No| F1{Currency provided?}
    F1 -->|Yes| F2{Currency exists?}
    F2 -->|No| F3[Return error: currency not found]
    F2 -->|Yes| G{At least one account identifier remains?}
    F1 -->|No| G
    G -->|No| H[Return error: missing account identifier]
    G -->|Yes| I[Update bank account record]
    I --> J[Return updated bank account]
```

## External Dependencies

- [primitives::Currency](../../../primitives/docs/models/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**: Neither accountNumber nor iban was provided

## Test Cases

- updates bank account details
- updates routingNumber
- updates swiftBic
- clears routingNumber when null is passed
- clears swiftBic when null is passed
- updates bank account for DRAFT partner
- updates bank account for ACTIVE partner
- updates bank account for INACTIVE partner
- returns error when account not found
- returns error when bank name is empty
- returns error when account holder name is empty
- returns error when currency not found
- returns error when update would remove all identifiers
