<?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 CsrRedemptionSetting extends Model
{
    use HasFactory,LogsActivityCustom, Timezone;

    protected $casts = [
        'created_at' => 'datetime:d-m-Y H:i:s',
   ];
    const ARCHIVED = 0;
    const UNARCHIVED = 1;
    const replaceData = [
        'is_active' => [
            0 => 'Archived',
            1 => 'Restored',
        ],
    ];
    protected static $recordEvents = ['deleted', 'created'];
    public $pageName = "CSR Redemption Settings";
    public $colName = "week";
    protected $fillable = [
        'week', 'type', 'value', 'is_active', 'created_at', 'updated_at'
    ];

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

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