<?php

namespace App\Models;

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

class Exam extends Model
{
    use HasFactory;

    protected $table = 'exams';
    
    protected $fillable = [
        'exam_name',
        'exam_type',
        'exam_year',
        'class_id',
        'start_date',
        'end_date',
        'description',
        'status',
        'created_by'
    ];

    protected $casts = [
        'start_date' => 'date',
        'end_date' => 'date',
        'exam_year' => 'integer',
        'status' => 'boolean'
    ];

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

    public function routines()
    {
        return $this->hasMany(ExamRoutine::class);
    }

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

    // Exam types
    public static function getExamTypes()
    {
        return [
            'weekly' => 'সাপ্তাহিক পরীক্ষা',
            'monthly' => 'মাসিক পরীক্ষা',
            'half_yearly' => 'অর্ধ-বার্ষিক পরীক্ষা',
            'final' => 'বার্ষিক পরীক্ষা',
            'model_test' => 'মডেল টেস্ট',
            'pre_test' => 'প্রি-টেস্ট',
            'entrance' => 'ভর্তি পরীক্ষা'
        ];
    }
}