<?php

namespace App\Models;

use App\Http\Traits\LogsActivityCustom;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Contracts\Activity;
use Spatie\Activitylog\LogOptions;
use App\Http\Traits\Timezone;

class SocialLink extends Model
{
    use HasFactory, LogsActivityCustom, Timezone;

    const replaceData = [
        'is_active' => [
            1 => 'Restored',
            2 => 'Archived',
        ],
    ];
    protected static $submitEmptyLogs = false;
    protected static $recordEvents = ['deleted', 'created'];
    public $pageName = "Social Link";
    public $colName = "name";
    protected $fillable = ['name', 'link', 'is_active', 'icon'];

    public function tapActivity(Activity $activity, string $eventName)
    {
        $activity->log_name = $eventName;
        if ($eventName == 'created') {
            $activity->description = $this->pageName . ' ' . $this->attributes['name'] . ' ' . $eventName;
        } elseif ($eventName == 'deleted') {
            $activity->description = $this->pageName . ' ' . $this->attributes['name'] . ' ' . $eventName;
        }
    }

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->useLogName('system')
            ->submitEmptyLogs(false)
            ->logFillable()
            ->logExcept(['created_at', 'updated_at']);
    }
}
