<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use OwenIt\Auditing\Auditable as AuditableTrait;
use OwenIt\Auditing\Contracts\Auditable;
use Illuminate\Notifications\Notification;

class Applicant extends Model implements Auditable
{
    use HasFactory, SoftDeletes, AuditableTrait, Notifiable;

    /**
     * The attributes that are NOT mass assignable.
     *
     */
    protected $guarded = [
        'deleted_at',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
    ];

    public function job(): BelongsTo
    {
        return $this->belongsTo(Mrf::class, 'job_id');
    }

    // Defining the relationship to the JobTitle model
    public function jobtitle(): BelongsTo
    {
        return $this->belongsTo(JobTitle::class, 'job_title', 'id'); // Assuming the foreign key is job_title_id
    }

    public function mrf(): BelongsTo
    {
        return $this->belongsTo(Mrf::class, 'job_id');
    }

    public function process_history(): HasMany
    {
        return $this->hasMany(ApplicantProcessHistory::class, 'applicant_id', 'id');
    }

    public function routeNotificationForMail($notification)
    {
        return $this->email;
    }
}
