<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ModelNumberRequest extends FormRequest
{
    /**
     * 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()
    {
        switch ($this->method()) {
            case 'POST': {
                return [
                    'model_number'=>'required|between:3,20|regex:/^[A-Za-z0-9\-\_]+$/|unique:device_model_numbers,model_number',
                ];
            }
            case 'GET':
            case 'PUT': {
                return [
                    'model_number'=>'required|between:3,20|regex:/^[A-Za-z0-9\-\_]+$/|unique:device_model_numbers,model_number',
                ];
            }
            case 'DELETE':
            default: {
                return [];
            }
        }

    }

    //自定义提示
    public function messages()
    {
        return [
            'model_number.required' => '型号不能为空！',
            'model_number.between' => '密码需要在3到20位之间',
            'model_number.regex' => '型号格式只能包括数字、字母、- 、_',
            'model_number.unique' => '型号已经存在',
        ];
    }
}
