<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class MataPelajaran extends Model
{
    use HasFactory;

    protected $table = 'mata_pelajaran';

    protected $fillable = [
        'tingkat_sekolah_id',
        'nama',
        'kode',
    ];

    public function tingkatSekolah()
    {
        return $this->belongsTo(TingkatSekolah::class);
    }

    public function guruMengajar()
    {
        return $this->hasMany(GuruMengajar::class);
    }

    public function ujian()
    {
        return $this->hasMany(Ujian::class);
    }

    public function scopeByTingkat($query, int $tingkatSekolahId)
    {
        return $query->where('tingkat_sekolah_id', $tingkatSekolahId);
    }
}
