<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Course extends Model
{
    //
    protected $fillable = [
        'title',
        'description',
        'is_paid',
        'duration',
        'price',
        'certificate_available',
        'video_url',
        'status',
        'image',
        'instructor',
    ];

    protected $casts = [
        'is_paid' => 'boolean',
        'certificate_available' => 'boolean',
    ];

    public function instructor() {
        return $this->belongsTo(User::class, 'instructor_id');
    }

    public function enrollments() {
        return $this->hasMany(CourseEnrollment::class);
    }

    public function lessons() {
        return $this->hasMany(CourseLesson::class)->orderBy('order');
    }
}
