# ActivateUser

## Permission Scope

user

## Overview

ActivateUser transitions a user from PENDING status to ACTIVE status, granting them full access to the system. This command is typically executed by an administrator after the user's identity has been verified and onboarding requirements are complete.

Only users in PENDING status can be activated. Attempting to activate an already active or inactive user will fail.

## Business Rules

- User must exist in the system
- User must be in PENDING status
- Transitions user status from PENDING to ACTIVE
- Recomputes permissions so any roles pre-assigned while PENDING take effect
- Generates USER_ACTIVATED audit event with actor ID, timestamp, and previous status

## Process Flow

```mermaid
flowchart TD
    A[Receive activate request] --> B{User exists?}
    B -->|No| C[Return error: USER_NOT_FOUND]
    B -->|Yes| D{Status is PENDING?}
    D -->|No| E[Return error: INVALID_STATUS_TRANSITION]
    D -->|Yes| F[Update status to ACTIVE]
    F --> G[Log USER_ACTIVATED audit event]
    G --> H[Return updated user]
```

## External Dependencies

- None

## Error Scenarios

- **USER_NOT_FOUND**: Specified user ID does not exist
- **INVALID_STATUS_TRANSITION**: Requested status transition is not allowed from the current status

## Test Cases

- throws when user does not exist
- throws when user is already ACTIVE
- throws when user is INACTIVE (use reactivateUser instead)
- activates PENDING user to ACTIVE
