<?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 DepositAddress extends Model
{
    use HasFactory, LogsActivityCustom, Timezone;
    protected $casts = [
        'created_at' => 'datetime:d-m-Y H:i:s',
   ];
    protected $table = 'deposit_addresses';

    protected static $recordEvents = ['deleted', 'created'];
    public $pageName = "DepositAddress";
    public $colName = "value";
    protected $fillable = [
        'name',
        'value',
        'contract_address'
    ];

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

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