<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Guarded;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;

#[Guarded(['id'])]
class Department extends Model
{
    use HasFactory, SoftDeletes;

    public function lecturers(): BelongsToMany
    {
        return $this->belongsToMany(Lecturer::class, 'lecturer_department');
    }

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

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

    public function currentLeader(): HasOne
    {
        return $this->hasOne(DepartmentLeadership::class)->whereNull('ended_at');
    }
}
