# UpdatePartnerAddress

## Permission Scope

partnerDetail

## Overview

updatePartnerAddress modifies an address through its owning BusinessPartner aggregate. The address fields (line1, line2, city, state, postalCode, country) can be updated individually, and the merged address is validated before saving. Existing addresses remain updatable whether the parent partner has status ACTIVE or INACTIVE.

## Business Rules

- Address must exist in the system
- The owning BusinessPartner aggregate is loaded with a row lock before the address is changed
- Updates are permitted whether the partner has `status=ACTIVE` or `status=INACTIVE`
- After merging the patch, line1, city, and postalCode must remain non-empty, and country must contain exactly two uppercase ASCII letters
- Address purpose and default selection belong to account usages, not PartnerAddress
- Only provided fields are updated; omitted fields retain their current values
- `line2` and `state` can be cleared with null

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B[Lock and load owning BusinessPartner aggregate]
    B --> C{Address exists?}
    C -->|No| D[Return error: address not found]
    C -->|Yes| E[Merge provided address fields]
    E --> F{Required fields and country format valid?}
    F -->|No| G[Return validation error]
    F -->|Yes| H[Save aggregate and return address ID]
```

## External Dependencies

- None

## Error Scenarios

- **ADDRESS_NOT_FOUND**: Specified address ID does not exist
- **MISSING_REQUIRED_ADDRESS_FIELD**: One or more required fields (line1, city, postalCode) are empty or not provided
- **INVALID_COUNTRY_CODE**: Country does not contain exactly two uppercase ASCII letters

## Test Cases

- updates an address through the BusinessPartner aggregate
- allows correction while the partner is inactive
- returns error when the address does not exist
- rejects an invalid country code
