<?php

namespace App\Models;

use App\Traits\FilterableTrait;
use App\Traits\LogsActivityTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class QrSetting extends Model
{
    use HasFactory, FilterableTrait, LogsActivityTrait;

    protected $fillable = [
        'key',
        'value',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
        ];
    }

    // Filterable configuration
    protected array $filterable = ['key', 'is_active'];
    protected array $searchable = ['key', 'value'];
    protected array $sortable   = ['id', 'key', 'created_at'];

    // Activity Log configuration
    public string $logName = 'qr_setting';
    public array $loggable = ['key', 'value', 'is_active'];

    /**
     * Scope: Only active
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /**
     * Scope: By key
     */
    public function scopeByKey($query, string $key)
    {
        return $query->where('key', $key);
    }
}
