# OpenPipelineItem

## Permission Scope

item

## Overview

Publishes a DRAFT item by setting lifecycle to OPEN. After publishing, the item appears in operational lists (kanban boards, external-facing queries) and can be moved between stages with MovePipelineItem.

## Business Rules

- PipelineItem must exist
- PipelineItem must be in DRAFT lifecycle
- PipelineItem lifecycle changes to OPEN
- The item's current stage is unchanged
- No PipelineStageTransition record is created (lifecycle change only)
- A [PipelineItemChange](../model/PipelineItemChange.md) row is appended (`DRAFT → OPEN`)

## Process Flow

```mermaid
flowchart TD
    A[Receive openPipelineItem input] --> B{PipelineItem exists?}
    B -->|No| C[Return ITEM_NOT_FOUND]
    B -->|Yes| D{PipelineItem DRAFT?}
    D -->|No| E[Return ITEM_NOT_DRAFT]
    D -->|Yes| F[Set item lifecycle to OPEN]
    F --> H[Append PipelineItemChange row - LIFECYCLE]
    H --> G[Return opened PipelineItem]
```

## External Dependencies

- None

## Error Scenarios

- **ITEM_NOT_FOUND**: Specified item ID does not exist
- **ITEM_NOT_DRAFT**: PipelineItem is not in DRAFT lifecycle

## Test Cases

- publishing a DRAFT item succeeds and sets lifecycle to OPEN
- item remains in current stage after publish
- writes a PipelineItemChange recording DRAFT → OPEN
- does not create a PipelineStageTransition record
- returns error when item not found
- returns error when opening an OPEN item (ITEM_NOT_DRAFT)
- returns error when opening a CLOSED item (ITEM_NOT_DRAFT)
