<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Course extends Model
{
    use HasFactory, SoftDeletes;

    protected $guarded = ['id'];

    public function lecturer(): BelongsTo
    {
        return $this->belongsTo(Lecturer::class);
    }

    public static function getOptionsForLecturer(Lecturer $lecturer): Collection
    {
        return static::query()
            ->where('lecturer_id', $lecturer->id)
            ->get();
    }

    public function materials(): HasMany
    {
        return $this->hasMany(Material::class);
    }

    public function studyGroups(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
    {
        return $this->belongsToMany(StudyGroup::class, 'study_group_courses');
    }
}
