# Partner Bank Account

## Overview

PartnerBankAccount is a reusable child entity in the global BusinessPartner aggregate. It remains in a separate database table, while create, update, deactivate, and reactivate operations go through the owning aggregate. It captures bank name, account holder, account number, optional routing number, and currency.

Transaction purpose is account-specific and is stored separately:

- CustomerBankAccountUsage assigns a bank account to RECEIPT or REFUND.
- SupplierBankAccountUsage assigns a bank account to PAYMENT or REFUND.
- Each Account may designate at most one default bank account per purpose.

The same bank record can be reused by multiple company-scoped accounts belonging to the same BusinessPartner.

## Business Purpose

- The parent BusinessPartner must exist.
- New bank details may be added only while the partner's `active` flag is `true`.
- New bank details start with `active=true` and are deactivated rather than physically deleted.
- Inactive bank details remain readable for historical references but cannot be assigned to new Account usages.
- Existing bank details may still be corrected while the partner is inactive.
- bankName and accountHolderName are required.
- Account number is required and must be non-empty.
- currencyId must reference an existing Currency.
- PartnerBankAccount does not contain account purpose or default state.
- A usage may reference only a bank account owned by the usage Account's BusinessPartner.
- Default uniqueness is enforced per Account and purpose.

## Process Flow

```mermaid
flowchart TD
    A[Create reusable PartnerBankAccount] --> B[Create or update Account]
    B --> C[Assign bank details through BankAccountUsage]
    C --> D[Choose PAYMENT, RECEIPT, or REFUND purpose]
    D --> E{Default for purpose?}
    E --> F[Persist usage]
```

## Scenario Patterns

- A supplier account selects one partner bank account as its default PAYMENT destination.
- A customer account assigns a different bank account for RECEIPT and REFUND purposes.
- Multiple company-scoped accounts reuse the same verified bank master record.

## Test Cases

- An inactive partner cannot receive new bank details.
- Existing bank details remain correctable while the partner is inactive.
- Required bank fields, account identifiers, and currency references are validated.
- PartnerBankAccount is persisted without purpose or default fields.
- Account creation rejects bank details owned by a different partner.
- An Account cannot have multiple defaults for the same bank purpose.

## Reference Links

- [PartnerBankAccount](../model/PartnerBankAccount.md)
- [CustomerBankAccountUsage](../model/CustomerBankAccountUsage.md)
- [SupplierBankAccountUsage](../model/SupplierBankAccountUsage.md)
