<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SesiKuis extends Model
{
    protected $fillable = [
        'user_id',
        'kurikulum_id',
        'nama',
        'sekolah',
        'kelas',
        'selesai_pada'
    ];

    protected $casts = [
        'selesai_pada' => 'datetime'
    ];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function kurikulum()
    {
        return $this->belongsTo(Kurikulum::class);
    }

    public function jawabankuis()
    {
        return $this->hasMany(JawabanKuis::class);
    }

    public function hasilsaw()
    {
        return $this->hasMany(HasilSaw::class)->orderBy('peringkat');
    }

    public function sudahselesai()
    {
        return !is_null($this->selesai_pada);
    }

    public function tandaiselesai()
    {
        $this->selesai_pada = now();
        $this->save();
    }


}
