# ReactivateAccount

## Permission Scope

accountManagement

## Overview

reactivateAccount transitions a GL account from INACTIVE back to ACTIVE status, making it eligible to receive journal postings again. Reactivation clears any previously mapped successor account, as the account is now directly available for use.

## Business Rules

- Target account must exist
- Parent CoA must be in ACTIVE status; reactivating an account under an ARCHIVED CoA is rejected. Note: the DRAFT CoA case is unreachable because account activation requires an ACTIVE CoA, so an INACTIVE account cannot exist under a DRAFT CoA
- Target account must be in INACTIVE status
- Reactivating a DRAFT or ACTIVE account fails with an invalid state transition error
- Reactivation clears any previously mapped successor account

## Process Flow

```mermaid
flowchart TD
    A[Receive reactivate request] --> B{Account exists?}
    B -->|No| C[Return error: not found]
    B -->|Yes| B2{Parent CoA is ACTIVE?}
    B2 -->|No| B3[Return error: CoA is not ACTIVE]
    B2 -->|Yes| D{Status is INACTIVE?}
    D -->|No| E[Return error: invalid state transition]
    D -->|Yes| F[Clear successor mapping]
    F --> G[Update status to ACTIVE]
    G --> H[Return reactivated account]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNT_NOT_FOUND**: Specified account ID does not exist
- **CHART_OF_ACCOUNTS_ARCHIVED**: Parent CoA is in ARCHIVED status and cannot be modified
- **INVALID_STATE_TRANSITION**: Requested state transition is not allowed from the current status

## Test Cases

- returns error when account does not exist
- returns error when parent CoA is ARCHIVED
- returns error when account is DRAFT
- returns error when account is already ACTIVE
- reactivates an INACTIVE account
- clears successor mapping on reactivation
