# Videos Module

## Purpose
Video upload and management for teachers. Videos are used as educational content and can be linked to classroom instances.

## Key Model — Video (`app/Models/Video.php`)

### Fields
- `teacher_id` — Owner
- `title`, `description` (json, translatable)
- `original_name`, `path`, `thumbnail_path` — File storage
- `size` (unsignedBigInteger, bytes) — File size for storage tracking
- `duration` (unsignedInteger, seconds), `mime_type` (string, 100)
- `is_locked` (boolean, default: false)

### Relationships
- `teacher()` → BelongsTo User

### Attributes
- `url`, `thumbnailUrl`, `hasThumbnail()`, `thumbnailOrDefault`
- `formattedSize` — Human-readable file size
- `formattedDuration` — Human-readable duration

### Lifecycle Events
- `video.uploaded` — On creation
- `file.uploaded` — Also dispatched on creation

## Feature Entitlement

| Feature | Scope | Default Limit |
|---------|-------|---------------|
| `available_storage_videos` | Teacher | 512 MB |

Storage consumption is calculated as `ceil(size / 1048576)` (bytes to MB).

## Video Streaming
- Custom controller: `VideoStreamController` (`app/Http/Controllers/VideoStreamController.php`)
- Routes: `/stream-video/{path}` — Streams video files securely
- Secondary implementation: `VideoStreamControllerCodex`

## Filament Resources
- `VideoResource` — CRUD for videos in Program panel

## JavaScript Assets
- `resources/js/video-thumbnail-generator.js` — Client-side thumbnail generation

## Related Workflows
- **[Feature Usage Tracking Workflow](../WORKFLOWS.md#8-feature-usage-tracking-workflow)** — Video uploads consume `available_storage_videos` feature via the usage observer
