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

    protected $fillable = [
        "resumption_time",
        "closing_time",
        "default_late_period",
        "org_id",
        "name"
    ];

    use LogsActivity;

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

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

    //Define Parent Relationships
    public function user()
    {
        return $this->hasOne(User::class, "time_id");
    }
}
