
# Admin API Specification

## Purpose
This API manages:
- videos
- packages
- schedules
- playback diagnostics

Base path example:

`/api`

## Authentication
Admin endpoints should require authenticated access.

Recommended:
- Azure AD or app-level auth
- role-based access for editors and admins

## Video Endpoints

### Create video record
`POST /api/videos`

Request:
```json
{
  "videoId": "sermon-2026-03-01",
  "title": "The Grace of God",
  "sourcePath": "/source/sermon-2026-03-01.mp4",
  "durationSec": 3120,
  "thumbnail": "/images/sermon-2026-03-01.jpg"
}
```

Response:
```json
{
  "ok": true,
  "videoId": "sermon-2026-03-01"
}
```

### Get video
`GET /api/videos/{videoId}`

### List videos
`GET /api/videos`

Optional query params:
- `q`
- `limit`
- `offset`
- `tag`

### Update video
`PUT /api/videos/{videoId}`

### Delete video
`DELETE /api/videos/{videoId}`

## Package Endpoints

### Create package
`POST /api/packages`

Request:
```json
{
  "packageId": "PKG-SUNDAY-CURRENT",
  "label": "Current Sunday Package",
  "durationHours": 4,
  "items": [
    { "videoId": "worship-021", "order": 1 },
    { "videoId": "sermon-2026-03-01", "order": 2 },
    { "videoId": "teaching-018", "order": 3 }
  ]
}
```

### Get package
`GET /api/packages/{packageId}`

### List packages
`GET /api/packages`

### Update package
`PUT /api/packages/{packageId}`

### Delete package
`DELETE /api/packages/{packageId}`

## Schedule Endpoints

### Create daily schedule
`POST /api/schedules`

Request:
```json
{
  "date": "2026-03-08",
  "blocks": [
    { "start": "00:00", "packageId": "PKG-NIGHT-01" },
    { "start": "04:00", "packageId": "PKG-MORNING-01" },
    { "start": "08:00", "packageId": "PKG-SUNDAY-CURRENT" },
    { "start": "12:00", "packageId": "PKG-SUNDAY-CURRENT" },
    { "start": "16:00", "packageId": "PKG-EVENING-01" },
    { "start": "20:00", "packageId": "PKG-SUNDAY-LAST" }
  ]
}
```

### Get schedule by date
`GET /api/schedules/{date}`

### Update schedule by date
`PUT /api/schedules/{date}`

### Delete schedule by date
`DELETE /api/schedules/{date}`

## Playback Diagnostics

### Current channel state
`GET /api/channel/now`

Response:
```json
{
  "timestamp": "2026-03-08T09:17:25",
  "blockStart": "08:00",
  "packageId": "PKG-SUNDAY-CURRENT",
  "resolvedPackageId": "PKG-SUNDAY-CURRENT-2026-03-08",
  "videoId": "teaching-018",
  "segmentIndex": 54
}
```

### Debug channel at arbitrary time
`GET /api/channel/debug?time=2026-03-08T09:17:25`

## Suggested JSON Schemas

### Video
```json
{
  "videoId": "string",
  "title": "string",
  "durationSec": 0,
  "sourcePath": "string",
  "hlsPath": "string",
  "thumbnail": "string",
  "tags": ["string"]
}
```

### Package
```json
{
  "packageId": "string",
  "label": "string",
  "durationHours": 4,
  "items": [
    { "videoId": "string", "order": 1 }
  ]
}
```

### Schedule
```json
{
  "date": "YYYY-MM-DD",
  "blocks": [
    { "start": "HH:mm", "packageId": "string" }
  ]
}
```
