# Courses & Lessons Module

## Purpose
Educational content management — teachers create courses with structured lessons for their students.

## Key Models

### Course (`app/Models/Course.php`)
- Uses `HasTranslations` — `title`, `description` are translatable
- **Fields:** `program_id`, `level_id`, `teacher_id`, `title`, `description`, `picture`, `is_active`
- **Relationships:**
  - `program()` → BelongsTo Program
  - `teacher()` → BelongsTo User (teacher)
  - `level()` → BelongsTo ProgramLevel
  - `lessons()` → HasMany Lesson
- **Feature:** Creation consumes `no_of_courses` (teacher subscription)
- **Lifecycle events:** `course.created`, `course.updated`, `course.deleted`

### Lesson (`app/Models/Lesson.php`)
- Uses `HasTranslations` — `title`, `description`, `address`, `location`, `resources` are translatable
- **Fields:** `course_id`, `teacher_id`, `title`, `description`, `picture`, `starts_at`, `duration_minutes`, `mode`, `link`, `address` (json), `location` (json), `resources` (json), `is_active`
- **Mode enum:** `physical`, `video`, `meeting`
- **Relationships:**
  - `course()` → BelongsTo Course
  - `teacher()` → BelongsTo User
  - `classroomInstances()` → HasMany ClassroomInstance
- **Feature:** Creation consumes `no_of_lessons` (teacher subscription)
- **Computed attributes:** `effective_type`, `effective_link`, `effective_address`, `effective_location` (fallback to classroom values)
- **Lifecycle events:** `lesson.created`, `lesson.updated`, `lesson.deleted`

### ProgramLevel (`app/Models/ProgramLevel.php`)
- Connects courses to program-specific levels

## Feature Entitlement

| Feature | Scope | Default Limit |
|---------|-------|---------------|
| `no_of_courses` | Teacher | 10 |
| `no_of_lessons` | Teacher | 50 |

## Business Rules
- Courses belong to a teacher within a program
- Lessons belong to a course
- Lessons have a mode (physical/video/meeting) determining delivery format
- Lessons can define their own resources/location/address with fallback to classroom values
- Course and lesson creation/deletion updates feature usage counters automatically

## Related Workflows
- **[Course → Lesson → Classroom Workflow](../WORKFLOWS.md#9-course--lesson--classroom-workflow)** — Creating courses, lessons, and delivering classroom sessions
