# DeactivateUser

## Permission Scope

user

## Overview

DeactivateUser transitions a user from ACTIVE status to INACTIVE status, revoking their access to the system while preserving their data for audit and historical purposes. This command is used when an employee leaves the organization, is terminated, or needs temporary access suspension.

Only users in ACTIVE status can be deactivated. User data, role assignments, and historical associations are preserved.

## Business Rules

- User must exist in the system
- User must be in ACTIVE status
- Transitions user status from ACTIVE to INACTIVE
- User data is preserved for audit purposes
- Existing role assignments remain but become inactive
- Generates USER_DEACTIVATED audit event with actor ID, timestamp, and previous status

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> B{User exists?}
    B -->|No| C[Return error: USER_NOT_FOUND]
    B -->|Yes| D{Status is ACTIVE?}
    D -->|No| E[Return error: INVALID_STATUS_TRANSITION]
    D -->|Yes| F[Update status to INACTIVE]
    F --> G[Log USER_DEACTIVATED 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 PENDING
- throws when user is already INACTIVE
- deactivates ACTIVE user to INACTIVE
