<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;

class PayGrade extends Model
{
    use HasFactory;

    protected $guarded = [];

    protected $casts = [
        'allowances' => 'array',
        'deductions' => 'array',
    ];


    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logAll()
            ->useLogName('Paygrade')
            ->logOnlyDirty()
            ->setDescriptionForEvent(fn(string $eventName) => "Paygrade '{$this->name}' has been {$eventName}")
            ->dontSubmitEmptyLogs();
    }


    public function paygroup()
    {
        return $this->belongsTo(PayGroup::class, "pay_group_id");
    }

    public function organisation()
    {
        return $this->belongsTo(Organisation::class, "organisation_id");
    }

    public function jobInfo()
    {
        return $this->hasMany(JobInfo::class);
    }
}
