# PartnerAddress

## Description

PartnerAddress is a child entity of BusinessPartner that stores structured addresses classified by purpose (BILLING, SHIPPING, REGISTERED, or OTHER). Each address carries the same structured format as the organization module's Site entity: line1, line2, city, state, postalCode, and country (ISO 3166-1 alpha-2). One address per partner per address type may be designated as the default.

Adding new addresses requires the partner to be in DRAFT or ACTIVE state; INACTIVE partners may only have existing addresses read or updated.

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- [createPartnerAddress](../commands/CreatePartnerAddress.md) - Add an address to a partner
- [updatePartnerAddress](../commands/UpdatePartnerAddress.md) - Update address fields
- [deletePartnerAddress](../commands/DeletePartnerAddress.md) - Remove an address (with referential integrity check)
- [setDefaultPartnerAddress](../commands/SetDefaultPartnerAddress.md) - Designate an address as the default for its type

### Query Definitions

- [GetPartnerAddress](../queries/GetPartnerAddress.md) - Retrieve an address by id
- [GetDefaultPartnerAddress](../queries/GetDefaultPartnerAddress.md) - Retrieve the default address for a partner and address type
- [ListPartnerAddressesByPartner](../queries/ListPartnerAddressesByPartner.md) - List addresses for a partner with optional type filter

### Models

- PartnerAddress

### Invariants

- `line1`, `city`, `postalCode`, `country`, and `addressType` are required at creation
- `line2` and `state` are optional
- `country` must be a valid ISO 3166-1 alpha-2 code
- `addressType` must be one of BILLING, SHIPPING, REGISTERED, OTHER
- `addressType` is immutable after creation; changing type requires deleting the old address and creating a new one
- A partner may hold multiple addresses of the same type
- Only one address per partner per addressType may be marked as default at any time
- A partner can have independent defaults for BILLING, SHIPPING, REGISTERED, and OTHER simultaneously
- Setting isDefault = true for an addressType automatically unsets isDefault on the previous default of the same type for the same partner
- Deleting the default address does not automatically promote another address of the same type to default; no default exists until one is explicitly set
- Deleting an address referenced on historical or open transactions is rejected (referential integrity)
- Adding new addresses requires the partner to be in DRAFT or ACTIVE state; adding to an INACTIVE partner is rejected
- Reading and updating existing addresses is permitted regardless of partner status (DRAFT, ACTIVE, or INACTIVE)
- A partner with no addresses returns an empty list, not an error
- When no default address exists for a requested type, the system returns an error rather than silently picking an arbitrary address

### Relationships

- **References BusinessPartner**: Each address belongs to exactly one BusinessPartner
