<?php

namespace App\Models;

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

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

    const DOMAIN_HOLDER = [
        'eu_vat_api' => 'eu_vat',
        'recaptcha_api' => 'recaptcha',
        'etherscan_api' => 'etherscan_api'
    ];
    const ENABLE = 1;
    const DISABLE = 0;

    // const for ApiSettings status
    protected static $recordEvents = ['deleted', 'created'];
    public $pageName = "API Settings";
    public $colName = "service_name";
    protected $guarded = [];
    protected $casts = [
        'status' => 'int','created_at' => 'datetime:d-m-Y H:i:s'
    ];

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

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