# ActivateAccount

## Overview

activateAccount transitions a GL account from DRAFT to ACTIVE status, making it eligible to receive journal postings from downstream modules. Only DRAFT accounts can be activated; already ACTIVE or INACTIVE accounts require different transitions.

## Business Rules

- Target account must exist
- Parent CoA must be in ACTIVE status; activating an account under a DRAFT CoA is rejected because the CoA itself has not yet been activated, and activating an account under an ARCHIVED CoA is rejected because archived CoAs are immutable
- Target account must be in DRAFT status
- Activating an already ACTIVE account fails with an invalid state transition error
- Activating an INACTIVE account fails (use reactivateAccount instead)

## Process Flow

```mermaid
flowchart TD
    A[Receive activate 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 DRAFT?}
    D -->|No| E[Return error: invalid state transition]
    D -->|Yes| F[Update status to ACTIVE]
    F --> G[Return activated account]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNT_NOT_FOUND**: Specified account ID does not exist
- **CHART_OF_ACCOUNTS_NOT_ACTIVE**: Parent CoA is not in ACTIVE status; account activation requires the CoA to be ACTIVE
- **INVALID_STATE_TRANSITION**: Entity is not in the required status for the requested state transition

## Test Cases

- returns error when account does not exist
- returns error when parent CoA is DRAFT
- returns error when parent CoA is ARCHIVED
- returns error when account is already ACTIVE
- returns error when account is INACTIVE
- activates a DRAFT account
