<?php

namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class LanguageVariables extends Model
{
    use HasFactory, HasTranslations;

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

    public $translatable = ['value'];

    public function scopeSearch($query, $search)
    {
        return $query->where('key', 'like', '%' . $search . '%')
        ->orWhere('value', 'like', '%' . $search . '%');
    }

    public static function getLanguageVariable($key)
    {
        $languageVariable = LanguageVariables::where('key', $key)->first();
        if ($languageVariable) {
            return $languageVariable->value;
        }
        return $key;
    }
}