<?php

namespace App\Models;

use CodeIgniter\Model;

class CandidateEducationModel extends Model
{
    protected $table         = 'candidate_education';
    protected $allowedFields = ['candidate_profile_id', 'institution', 'degree', 'field_of_study', 'start_year', 'end_year', 'grade'];
    protected $validationRules = [
        'institution' => 'required|max_length[150]',
        'degree'      => 'required|max_length[150]',
    ];

    public function forProfile(int $candidateProfileId): array
    {
        return $this->where('candidate_profile_id', $candidateProfileId)->orderBy('end_year', 'DESC')->findAll();
    }
}
