<?php

namespace App\Models;

use App\Traits\Auditable;
use App\Traits\DeleteGuarded;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Position extends Model
{
    use HasFactory, SoftDeletes, Auditable, DeleteGuarded;

    protected $fillable = ['department_id', 'name', 'description', 'email', 'creator_by', 'last_updated_by', 'deleted_by'];


    public const DELETE_PREVENTING_RELATIONSHIPS = [];
    public const DELETE_AFFECTED_RELATIONSHIPS = [];
    public const NON_STANDALONE_CHILDREN = [];
    /**
     * Get the audit descriptions for different actions.
     *
     * @return array An array containing descriptions for different audit actions
     */
    protected function getAuditDescriptions(): array
    {
        return [
            'create' => "Created new position: $this->name",
            'update' => "Updated position details: $this->name",
            'delete' => "Deleted position: $this->name",
        ];
    }

    /**
     * Get the department under which the position belongs.
     *
     * @return BelongsTo
     */
    public function department(): BelongsTo
    {
        return $this->belongsTo(Department::class);
    }

    /**
     * Get the user who created the position.
     *
     * @return BelongsTo
     */
    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    /**
     * Get the user who last updated the position.
     *
     * @return BelongsTo
     */
    public function last_updater(): BelongsTo
    {
        return $this->belongsTo(User::class, 'last_updated_by');
    }
}
