<?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\HasOne;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;

class OrganisationEmployeePension extends Model
{
    use HasFactory;

    protected $fillable = [
        "pension_id",
        "employee_id",
        "org_id"
    ];


    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 a pension plan")
            ->dontSubmitEmptyLogs();
    }


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

    public function pension()
    {
        return $this->belongsTo(OrganisationPensions::class, "pension_id");
    }
}