<?php

namespace App\DataTables;

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

class RoleDataTableEditor extends DataTablesEditor
{
  protected $model = Role::class;
  protected $messages = [
    'display_name.required' => 'Il nome è richiesto',
    'name.unique' => 'Nome non valido'
  ];

  /**
  * Get create action validation rules.
  *
  * @return array
  */
  public function createRules()
  {

    return [
      'display_name'  => 'required',
      'name' => 'unique:roles'
    ];
  }

  public function createMessages(){
    return $this->messages;
  }

  /**
  * Get edit action validation rules.
  *
  * @param Model $model
  * @return array
  */
  public function editRules(Model $model)
  {
    return [
      'display_name'  => 'required|unique:roles',
    ];
  }

  public function editMessages(){
    return $this->messages;
  }

  /**
  * Get remove action validation rules.
  *
  * @param Model $model
  * @return array
  */
  public function removeRules(Model $model)
  {
    return [];
  }

  public function creating(Model $model, array $data)
  {
    return $data;
  }

  public function updating(Model $model, array $data)
  {
    return $data;
  }
}
