<?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 Level extends Model
{
    use HasFactory, LogsActivityCustom, Timezone;
    protected $casts = [

        'created_at' => 'datetime:d-m-Y H:i:s'
    ];
    protected $fillable = [
        'level_name',
        'level_no',
        'color_code',
        'status',
        'user_id',
    ];
    const replaceData = [
        'status' => [
            1 => 'Archived',
            2 => 'Restored',
        ],
    ];
    protected static $submitEmptyLogs = false;
    protected static $recordEvents = ['deleted', 'created'];
    public $pageName = "Sponsor Level";
    public $colName = "level_name";

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

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