# DeactivatePipeline

## Permission Scope

pipeline

## Overview

Archives an active pipeline, preventing new items from being added. Existing items remain readable. The operation is idempotent -- deactivating an already-archived pipeline succeeds without error.

## Business Rules

- Pipeline must exist
- Pipeline must be ACTIVE to transition to ARCHIVED
- If pipeline is already ARCHIVED, the operation is idempotent (no error)
- Existing items on the pipeline remain accessible after archiving

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivatePipeline input] --> B{Pipeline exists?}
    B -->|No| C[Return PIPELINE_NOT_FOUND]
    B -->|Yes| D{Pipeline status?}
    D -->|ACTIVE| E[Set status to ARCHIVED]
    E --> F[Return archived Pipeline]
    D -->|ARCHIVED| F
    D -->|other| G[Return INVALID_STATUS_TRANSITION]
```

## External Dependencies

- None

## Error Scenarios

- **PIPELINE_NOT_FOUND**: Specified pipeline ID does not exist
- **INVALID_STATUS_TRANSITION**: Pipeline is in a status that cannot transition to ARCHIVED (not ACTIVE or ARCHIVED)

## Test Cases

- archives an active pipeline
- is idempotent when pipeline is already archived
- returns error when pipeline not found
- returns INVALID_STATUS_TRANSITION when the stored status is outside the lifecycle
