# Partner Lifecycle

## Overview

BusinessPartner is the globally unique identity for an external organization or individual. Company, currency, approval, and transaction-specific configuration belong to CustomerAccount or SupplierAccount rather than the identity record.

Each BusinessPartner, CustomerAccount, and SupplierAccount is created with `status=ACTIVE`. Each may later transition to `INACTIVE` and back independently. Accounts reference the global identity through `partnerId`; approval or registration workflow is outside the Account lifecycle and may be introduced as a separate aggregate when required.

## Business Purpose

- Keep legal identity and shared contact data in one place.
- Allow the same identity to transact through several company or department accounts.
- Prevent new Accounts from being created for an inactive partner.
- Preserve historical identity even when individual Accounts are retired.

## Process Flow

```mermaid
stateDiagram-v2
    [*] --> Active: createPartner (status=ACTIVE)
    Active --> Inactive: deactivatePartner
    Inactive --> Active: reactivatePartner
```

## Scenario Patterns

- An active global partner receives separate supplier accounts for two companies.
- The same partner receives both customer and supplier accounts without duplicating identity data.
- An inactive partner is reactivated before a new account is opened.

```mermaid
flowchart TD
    A[active BusinessPartner] --> B[Create active company-scoped Account]
    B --> C[Reference Account from transactions]
    C --> D[Deactivate Account when the company-scoped relationship stops]
    D --> E[Reactivate Account when the relationship resumes]
```

## Test Cases

- A partner is created with `status=ACTIVE`.
- Partner name and type are validated by the aggregate.
- Deactivation transitions `ACTIVE` to `INACTIVE`; reactivation transitions it back to `ACTIVE`.
- Business partners are never physically deleted; deactivation preserves stable references.
- BusinessPartner has no company or preferred-currency field.
- CustomerAccount and SupplierAccount creation require an active partner.
- CustomerAccount and SupplierAccount are active when created.
- Accounts may be deactivated and later reactivated independently of the BusinessPartner.
- Account records are deactivated rather than physically deleted, so their codes and history remain traceable.
- Downstream transactions require both the selected Account and its BusinessPartner to have `status=ACTIVE`.
- Any future registration or approval workflow is modeled separately and creates an active Account on approval.

## Reference Links

- [BusinessPartner](../model/BusinessPartner.md)
- [CustomerAccount](../model/CustomerAccount.md)
- [SupplierAccount](../model/SupplierAccount.md)
