<?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\Contracts\Auditable;
use OwenIt\Auditing\Auditable as AuditableTrait;

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

    protected $table = 'mrf';
     /**
     * 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 employee(): BelongsTo
    {
        return $this->belongsTo(Employee::class, 'requested_by', 'employee_id');
    }

    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class, 'company_id');
    }

    public function jobtitle(): BelongsTo
    {
        return $this->belongsTo(JobTitle::class, 'job_title');
    }

    public function employmenttype(): BelongsTo
    {
        return $this->belongsTo(EmploymentType::class, 'employment_status');
    }

    public function applicants(): HasMany
    {
        return $this->hasMany(Applicant::class, 'job_id', 'id');
    }

    public function requestor(): HasMany
    {
        return $this->hasMany(Employee::class, 'employee_id', 'requested_by');
    }

    public function recommendor(): HasMany
    {
        return $this->hasMany(Employee::class, 'employee_id', 'recommended_by');
    }

    public function endorser(): HasMany
    {
        return $this->hasMany(Employee::class, 'employee_id', 'endorsed_by');
    }

    public function approver(): HasMany
    {
        return $this->hasMany(Employee::class, 'employee_id', 'approved_by');
    }

    public function nature(): BelongsTo
    {
        return $this->belongsTo(NatureOfRequest::class, 'nature_of_request');
    }

    public function job_classification(): BelongsTo
    {
        return $this->belongsTo(JobClassification::class, 'classification');
    }
}
