# Content API Reference

The Content API provides structured input handling for presentations from any source.

## Content Structure

All content follows this JSON schema:

```javascript
{
  "metadata": {
    "title": "Presentation Title",
    "brand": "ce|phat|custom",
    "theme": "default|liquid-gold|custom",
    "version": "1.0",
    "author": "Optional",
    "created": "ISO timestamp"
  },
  "slides": [
    // Array of slide objects
  ]
}
```

## Slide Types

### Title Slide

```javascript
{
  "id": "unique-slide-id",
  "type": "title",
  "content": {
    "headline": "Main Title",
    "subline": "Subtitle or tagline"
  },
  "layout": {
    "alignment": "center|left|right",
    "background": "default|image|gradient"
  }
}
```

### Content Slide

```javascript
{
  "id": "unique-slide-id", 
  "type": "content",
  "content": {
    "headline": "Slide Title",
    "body": "Main content text",
    "bullets": ["Point 1", "Point 2"],
    "footnote": "Optional footnote"
  },
  "layout": {
    "alignment": "left|center|right",
    "columns": 1|2,
    "bullet_style": "default|numbered|none"
  }
}
```

### Image Slide

```javascript
{
  "id": "unique-slide-id",
  "type": "image", 
  "content": {
    "headline": "Image Title",
    "image": "assets/images/filename.jpg",
    "caption": "Image description",
    "alt": "Alt text for accessibility"
  },
  "layout": {
    "image_position": "center|left|right|background",
    "image_size": "contain|cover|auto",
    "text_overlay": true|false
  }
}
```

### Split Slide (Text + Image)

```javascript
{
  "id": "unique-slide-id",
  "type": "split",
  "content": {
    "headline": "Split Content",
    "text": "Text content for one side",
    "image": "assets/images/filename.jpg",
    "image_caption": "Optional caption"
  },
  "layout": {
    "split_ratio": "50-50|60-40|40-60|70-30",
    "text_side": "left|right",
    "alignment": "top|center|bottom"
  }
}
```

### Data Slide (Charts/Graphs)

```javascript
{
  "id": "unique-slide-id",
  "type": "data",
  "content": {
    "headline": "Data Visualization",
    "chart_type": "bar|line|pie|table",
    "data": {
      // Chart data structure
    },
    "insights": ["Key insight 1", "Key insight 2"]
  },
  "layout": {
    "chart_position": "center|left|right",
    "show_legend": true|false,
    "color_scheme": "brand|monochrome|custom"
  }
}
```

## Content API Methods

### Python API

```python
from content_api import ContentAPI

# Initialize
api = ContentAPI('/path/to/project')

# Load existing content
content = api.load_content()

# Add new slide
slide_data = {
    "id": "slide-new",
    "type": "content", 
    "content": {"headline": "New Slide"}
}
api.add_slide(slide_data)

# Update slide
api.update_slide("slide-id", slide_data)

# Remove slide
api.remove_slide("slide-id")

# Reorder slides
api.reorder_slides(["slide-1", "slide-3", "slide-2"])

# Save content
api.save_content(content)
```

### CLI Usage

```bash
# View current content
python scripts/apis/content_api.py /path/to/project

# Add slide from template
python scripts/apis/content_api.py /path/to/project add-slide title

# Import from external source
python scripts/apis/content_api.py /path/to/project import chat-log.txt
python scripts/apis/content_api.py /path/to/project import presentation.pptx
python scripts/apis/content_api.py /path/to/project import --api-endpoint https://api.example.com/slides
```

## Content Sources

### Chat/Text Import

Import structured content from chat conversations or text files:

```bash
python scripts/apis/content_api.py project import --source chat --file conversation.txt
```

Expected format:
```
Slide 1: Title
Main headline
Subtitle text

Slide 2: Business Model  
Content about business model
- Key point 1
- Key point 2
- Key point 3
```

### PowerPoint Import

Extract content from existing PowerPoint files:

```bash
python scripts/apis/content_api.py project import --source pptx --file presentation.pptx
```

Extracts:
- Slide titles and text content
- Image references (copies to assets)
- Basic layout information

### API Import

Connect to external APIs for content:

```bash
python scripts/apis/content_api.py project import --source api \
  --endpoint "https://api.notion.com/v1/pages/123" \
  --headers "Authorization: Bearer token"
```

### Manual Entry

Interactive content creation:

```bash
python scripts/apis/content_api.py project interactive
```

Prompts for:
- Slide type selection
- Content input for each field
- Layout preferences

## Validation

The Content API validates all content against the schema:

### Required Fields
- `slides[].id` - Unique identifier
- `slides[].type` - Must be valid slide type
- `slides[].content` - Must contain required fields for slide type

### Constraints
- IDs must be unique across slides
- Image paths must exist in assets directory
- Layout options must be valid for slide type

### Error Handling

```python
try:
    api.add_slide(invalid_slide)
except ValidationError as e:
    print(f"Validation failed: {e.message}")
    print(f"Field: {e.field}")
    print(f"Value: {e.value}")
```

Common validation errors:
- Missing required content fields
- Invalid slide type
- Duplicate slide IDs
- Invalid layout options
- Missing asset files