<?php

namespace App\DataTables\ProductManagement\Tags;

use App\Models\ProductManagement\Tag;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rule;
use Yajra\DataTables\DataTablesEditor;

class TagDataTableEditor extends DataTablesEditor{
    protected $model = Tag::class;

    /**Get create action validation rules.
     * @return array
     */
    public function createRules(){
        $tag_table = $this->resolveModel()->getTable();

        return  [
            "name" => ["required",'min:2',
                Rule::unique($tag_table,"name")
                   ],
            "active" => ['nullable'],
        ];
    }

    /**Get edit action validation rules.
     * @param Model $model
     * @return array
     */
    public function editRules(Model $model){
        $tag_table = $this->resolveModel()->getTable();
        return  [
            "name" => ["required",'min:2',
                Rule::unique($tag_table,"name")
                    ->ignore($model->getKey())

            ],
            "active" => ['required'],
        ];
    }

    /**
     * @return array
     */
    public function attributes(){
        return [
            "name" => __("Name"),
            "active" => __("Status"),
        ];
    }

}
