<?php
namespace App\Repositories\Eloquent;
use App\Models\ProfessionalEducation;
use App\Repositories\Interfaces\ProfessionalEducationRepositoryInterface;

class ProfessionalEducationRepository extends BaseRepository implements ProfessionalEducationRepositoryInterface
{
    public function __construct(ProfessionalEducation $model) { parent::__construct($model); }
    public function replaceForProfessional(int $professionalId, array $educations): void {
        $this->model->where('professional_id', $professionalId)->delete();
        foreach ($educations as $education) $this->model->create([...$education, 'professional_id' => $professionalId]);
    }
    public function forProfessional(int $professionalId): array {
        return $this->model->where('professional_id', $professionalId)->orderByDesc('end_year')->get()->toArray();
    }
}
