<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;

class AcademyCourseLesson extends Pivot
{
    protected $table = 'academy_course_lessons';

    public $incrementing = true;

    protected $fillable = [
        'course_id',
        'section_id',
        'lesson_id',
        'order_num',
        'is_required',
        'access_override',
        'unlock_after_lesson_id',
    ];

    protected $casts = [
        'order_num' => 'integer',
        'is_required' => 'boolean',
    ];

    public function course(): BelongsTo
    {
        return $this->belongsTo(AcademyCourse::class, 'course_id');
    }

    public function section(): BelongsTo
    {
        return $this->belongsTo(AcademyCourseSection::class, 'section_id');
    }

    public function lesson(): BelongsTo
    {
        return $this->belongsTo(AcademyLesson::class, 'lesson_id');
    }

    public function unlockAfterLesson(): BelongsTo
    {
        return $this->belongsTo(AcademyLesson::class, 'unlock_after_lesson_id');
    }
}