<?php

namespace App\Models;

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

class Penilaian extends Model
{
    use HasFactory;

    protected $fillable = [
        'guru_id',
        'kelas_id',
        'subject_id',
        'tanggal',
        'jenis_penilaian',
        'skala_penilaian', // <--- INI WAJIB ADA AGAR TERSIMPAN
        'topik'
    ];

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

    public function kelas()
    {
        return $this->belongsTo(Kelas::class);
    }

    // --- PERBAIKAN DI SINI ---
    // Nama relasi: subject
    // Foreign Key: subject_id (otomatis terdeteksi oleh Laravel karena namanya sesuai)
    public function subject()
    {
        return $this->belongsTo(Subject::class); 
    }

    public function details()
    {
        return $this->hasMany(PenilaianDetail::class);
    }
}