<?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 TransferAddress extends Model
{
    use HasFactory, LogsActivityCustom, Timezone;
    protected $casts = [
        'created_at' => 'datetime:d-m-Y H:i:s'
    ];
    protected static $submitEmptyLogs = false;
    protected static $recordEvents = ['deleted', 'created'];
    public $pageName = "Transfer Address";
    public $colName = "address";
    protected $table = 'transfer_addresses';
    protected $fillable = [
        'user_id', 'note', 'address'
    ];

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

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