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

class PersonnelActionForm extends Model implements Auditable

{
    use HasFactory, SoftDeletes, AuditableTrait;

    /**
     * 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, 'employee_id', 'employee_id');
    }

    public function previous_position(): BelongsTo
    {
        return $this->belongsTo(JobTitle::class, 'position_id', 'id');
    }

    public function next_position(): BelongsTo
    {
        return $this->belongsTo(JobTitle::class, 'position', 'id');
    }

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

    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 type_of_movement(): BelongsTo
    {
        return $this->belongsTo(TypeOfMovement::class, 'nature_of_request_id');
    }

    public function unit(): BelongsTo
    {
        return $this->belongsTo(Unit::class, 'unit');
    }
}
