<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Guru;
use App\Models\PesertaChallenge;

class Challenge extends Model
{
    use HasFactory;

    protected $table = 'challenges';  

    protected $primaryKey = 'id_challenge';

    protected $fillable = [
        'id_guru',
        'judul_challenge',
        'deskripsi',
        'exp',
        'id_badge',
        'durasi_pengerjaan',
        'tenggat_waktu',
    ];
    protected $casts = [
        'durasi_pengerjaan' => 'integer',
    ];

    public function kelas()
{
    return $this->belongsToMany(
        Kelas::class,
        'challenge_kelas',
        'id_challenge',
        'id_kelas'
    );
}

public function soal()
{
    return $this->hasMany(SoalChallenge::class, 'id_challenge');
}

public function peserta()
{
    return $this->hasMany(PesertaChallenge::class, 'id_challenge');
}

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

}