<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Spatie\Activitylog\Contracts\Activity;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use App\Http\Traits\Timezone;

class ContactUs extends Model
{
    use HasFactory, LogsActivity, Timezone;
    protected $casts = [
        'created_at' => 'datetime:d-m-Y H:i:s',
   ];
    protected static $logName = 'system';
    protected static $logAttributes = ['*'];
    protected static $logAttributesToIgnore = ['created_at', 'updated_at'];
    protected static $logOnlyDirty = true;
    protected static $submitEmptyLogs = false;
    protected $fillable = ['first_name', 'last_name', 'email', 'message'];

    public function tapActivity(Activity $activity, string $eventName)
    {
        $activity->log_name = $eventName;
        $activity->description = 'record ' . $eventName . ' by ' . (Auth::user() && isset(Auth::user()->details->email) ? Auth::user()->details->email : ($this->email ?? ''));
        $activity->causer_id = Auth::user() && isset(Auth::user()->id) ? Auth::user()->id : ($this->id ?? '');
        $activity->causer_type = Auth::user() && Auth::user()->getMorphClass() !== null ? Auth::user()->getMorphClass() : ($this->getMorphClass() ?? '');
    }

    public function getActivitylogOptions(): LogOptions
    {
        // TODO: Implement getActivitylogOptions() method.
    }
}
