<?php

namespace App\Models;

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

class Marksheet extends Model
{
    use HasFactory;

    protected $table = 'marksheets';
    
    protected $fillable = [
        'student_id',
        'class_id',
        'exam_type',
        'exam_name',
        'exam_year',
        'total_marks',
        'obtained_marks',
        'percentage',
        'gpa',
        'grade',
        'rank',
        'total_students',
        'remarks',
        'published_date',
        'published_by'
    ];

    protected $casts = [
        'exam_year' => 'integer',
        'total_marks' => 'integer',
        'obtained_marks' => 'decimal:2',
        'percentage' => 'decimal:2',
        'gpa' => 'decimal:2',
        'rank' => 'integer',
        'total_students' => 'integer',
        'published_date' => 'date'
    ];

    public function student()
    {
        return $this->belongsTo(Student::class);
    }

    public function class()
    {
        return $this->belongsTo(Classes::class, 'class_id');
    }

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

    public function results()
    {
        return $this->hasMany(Result::class, 'marksheet_id');
    }
}