<?php

namespace App\Models;

use App\Enums\QualificationType;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Qualification extends Model
{
    use HasFactory;

    protected $fillable = [
        'applicant_id', 'qualification_type', 'institution', 'award',
        'year', 'index_number', 'gpa', 'total_points',
    ];

    protected function casts(): array
    {
        return [
            'qualification_type' => QualificationType::class,
            'gpa' => 'decimal:2',
        ];
    }

    public function applicant(): BelongsTo
    {
        return $this->belongsTo(Applicant::class);
    }

    public function subjects(): HasMany
    {
        return $this->hasMany(QualificationSubject::class);
    }

    public function typeLabel(): string
    {
        return $this->qualification_type->label();
    }
}
