<?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 OrganisationTaxEmployee extends Model
{
    use HasFactory;

    protected $fillable = [
        "org_id",
        "employee_id",
        "tax_id",
        "is_exempted",
        "personal_rate"
    ];

    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logAll()
            ->useLogName('TaxEmployee')
            ->logOnlyDirty()
            ->setDescriptionForEvent(fn(string $eventName) =>"Employee with the email of '" . optional($this->user)->email . "' has been {$eventName} from a tax settings")
            ->dontSubmitEmptyLogs();
    }



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