# DeactivatePartner

## Permission Scope

partner

## Overview

deactivatePartner changes a business partner's `status` from `ACTIVE` to `INACTIVE`. Inactive partners cannot receive new transaction accounts, while their identity and historical references are preserved.

## Business Rules

- Partner must exist in the system
- The BusinessPartner aggregate is loaded with a row lock before its status is changed
- Partner must have `status=ACTIVE`
- After deactivation, new accounts, addresses, and bank details cannot be added to the partner
- Existing account statuses and resource availability flags are unchanged

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> A1[Lock and load BusinessPartner aggregate]
    A1 --> B{Partner exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| D{status is ACTIVE?}
    D -->|No| E[Return error: invalid state transition]
    D -->|Yes| F[Set status to INACTIVE]
    F --> G[Save aggregate and return partner ID]
```

## External Dependencies

- None

## Error Scenarios

- **PARTNER_NOT_FOUND**: Specified partner ID does not exist
- **INVALID_STATE_TRANSITION**: Requested state transition is not allowed from the current status

## Test Cases

- sets an active partner to inactive
- returns error when partner not found
- returns error when partner is already inactive
