<?php

namespace App\Http\Requests;

use App\Http\Response\ResponseJson;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class ModeratorRequest extends FormRequest
{
    use ResponseJson;
    /**
     * 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<string, mixed>
     */
    public function rules()
    {
        return [
            'name'  =>  'required|max:11',
            'birthday'    =>  'required|date',
            'sex'   =>  'required|in:1,2',
            'apply_date'    =>  'required|date',
            'dma_date'  =>  'required|date',
            'mobile'    =>  'required|numeric|digits:11',
            'reason'    =>  'required|max:800',
            'promote'    =>  'required|max:800',
            'quality'    =>  'required|max:800',
            'suggest'    =>  'required|max:800',
        ];
    }

    public function messages()
    {
        return [
            'name.required' => '请输入真实姓名',
            'name.max'  =>  '姓名长度超出最大值',
            'birthday.required' =>  '请选择年龄',
            'birthday.date'=>'请选择正确的年龄',
            'sex.required'  =>  '请选择性别',
            'sex.in'     =>  '请选择正确性别',
            'apply_date.required'   => '请选择申请日期',
            'apply_date.date'    =>  '请选择正确申请日期',
            'dma_date.required' =>  '请选择DMA起始日期',
            'dma_date.date'  =>     '请选择正确DMA起始日期',
            'mobile.required'   =>  '请输入联系电话',
            'mobile.numeric'    =>   '请输入正确联系电话',
            'mobile.digits'    =>  '联系电话字数超过最大值',
            'reason.required'    =>  '请输入正确的理由',
            'reason.max'    =>  '输入理由字数超过最大值',
            'promote.required'=>    '情输入需要提升的技能',
            'promote.max'=>    '输入的需要提升的技能的字数超出最大值',
            'quality.required'=>    '情输入需要的素质和能力',
            'quality.max'=>    '输入的需要的素质和能力字数超出最大值',
            'suggest.required'=>    '情输入您的建议和想法',
            'suggest.max'=>    '输入的建议和想法的字数超出最大值',
        ];
    }

    public function failedValidation(Validator $validator)
    {
        $msg = $validator->errors()->first();
        throw new HttpResponseException($this->failure($msg));
    }
}
