<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MenuRequest extends FormRequest
{
    private $table            = 'menu';
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->id;

        $condName   = '';
        $condOrdering = '';
        $condLink    = '';
        $condStatus    = '';
        $condTypeMenu   = '';
        $condTypeOpen = '';

        $condName  = "bail|required|unique:$this->table,name";

        if(!empty($id)){ // edit
            $condName  .= ",$id";
        }
        $condStatus     = 'bail|in:active,inactive';
        $condTypeMenu      = 'bail|in:link,category_product,category_article';
        $condTypeOpen      = 'bail|in:new_window,new_tab,current';

        return [
            'name' => $condName,
            'ordering' => $condOrdering,
            'link'    => $condLink,
            'status'   => $condStatus,
            'type_menu'    => $condTypeMenu,
            'type_open'   => $condTypeOpen
        ];
    }

    public function messages()
    {
        return [
            // 'name.required' => 'Name không được rỗng',
            // 'name.min'      => 'Name :input chiều dài phải có ít nhất :min ký tứ',
        ];
    }
    public function attributes()
    {
        return [
            // 'description' => 'Field Description: ',
        ];
    }
}
