<?php

namespace Yajny\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Yajny\Traits\SelectTranslations;

use Spatie\Searchable\Searchable;
use Spatie\Searchable\SearchResult;
use Spatie\Searchable\Search;
use Yajny\Traits\HasSitemap;

class Brand extends Model implements Searchable
{
    use HasTranslations ,SelectTranslations ;
    use HasSitemap;


    protected $table = 'brands';
    protected $primaryKey = 'id';
    public $translatable = ['name', 'description', 'h1_tag', 'h2_tag', 'meta_title', 'meta_desc', 'meta_kw'];

    public  $selColmns = ['id','slug','name','icon','offers_count'];
    protected $fillable = ['filter','offers_count'];

    public  $apiSelColmns = ['id','slug','name','icon','description','filter','header_image','offers_count'];

    public $casts = [
        'filter' => 'array',
        'recom_store' => 'array'
    ];

    public static function getHpBrands(){

        return PageWidget::where('for_page','homepage')->where('widget_type','BrandsGrid')->where('status',1)->pluck('widget_content')->first();

    }

    public function getSearchResult(): SearchResult
    {
        $locale = app()->getLocale();
        if (request('region')) {
            $locale .= "-" . request('region');
        }
        $url = ( config('app.purpose') == 'frontend' ) ? route('brand.name', [$locale, $this->slug]) : '';

        return new \Spatie\Searchable\SearchResult(
           $this,
           $this->name_lang ?? $this->name,
           $url
        );
    }


}
