<?php

namespace App\Models;
use App\Models\Eleve;

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

class Score extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'coefficient',
        'average',
        'rank',
        'sum',
        'sum_coeff',
        'type',
        'eleve_id',
        'dispenser',
        'classe_id',


    ];
    public function studentGrades()
    {
        return $this->hasMany(StudentGrade::class, 'score_id');
    }

    // Inverse of the one-to-many relationship with eleve
    public function eleve()
    {
        return $this->belongsTo(Eleve::class);
    }
    // Inverse of the one-to-many relationship with eleve
    public function classe()
    {
        return $this->belongsTo(Classe::class);
    }
    
    

    public static function isDispenserActive(int $eleveId, int $semester): bool
    {
        return self::where('eleve_id', $eleveId)
            ->where('type', $semester) 
            ->where('dispenser', 'true') 
            ->exists();
    }
}
