<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;


class Brand extends GenericModel
{
    use HasFactory;

    protected $table = 'brands';
    protected $primaryKey = 'id';
    protected $label = 'Brands';
    protected $sub_label = 'Brands';
    protected $fields = [
        'company'=>'Company',
        'nom'=>'Name',
    ];

    protected $orderBys = ['nom'=>'asc'];
    protected $actions = ['edit','add','delete'];
    protected $formRequireds = [ 'nom'];
    protected $numbers= ['bad_rating_score_threshold'];

    protected $belongsTo = [
        'company'=>[Entreprise::class,'entreprise_id','nom'],
    ];

    public function stores(){
        return $this->hasMany(Store::class);
    }

    public function company(){
        return $this->belongsTo(Entreprise::class);
    }

    public static function validate($request){
        $rules = [
            'nom' => 'required|unique:Brands,nom,'.$request->get('_id'),
        ];
        $messages = [
        ];
        return Validator::make($request->input(),$rules,$messages);
    }
}
