<?php

namespace App\Models;

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

class OrganisationEmployeeAllowance extends Model
{
    use HasFactory;
    protected $with = ['organisationAllowance'];
    protected $fillable = [
        "org_id",
        "employee_id",
        "allowance_id",
        "value",
        "is_annual",
        "start_date",
        "end_date"
    ];

    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logAll()
            ->useLogName('EmployeePension')
            ->logOnlyDirty()
            ->setDescriptionForEvent(fn(string $eventName) => "Employee with the email of '". optional($this->user)->email . "' has been {$eventName} on an allowance plan")
            ->dontSubmitEmptyLogs();
    }

    //Define Child Relationships
    public function user()
    {
        return $this->belongsTo(User::class, "employee_id");
    }

    public function organisationAllowance()
    {
        return $this->belongsTo(OrganisationAllowance::class, "allowance_id");
    }
}
