<?php

namespace App\Http\Requests;

use App\Services\LogService;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Validator;

class ForeignHaiRobotic_taskUpdateRequest 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()
    {
        return [
           'groupCode'=>'required',
           'taskCode'=>'required',
           'updateEventType'=>'required|in:0,1',
           'status'=>'required',//|in:0,1
//           'binCode'=>'required',
//           'kubotId'=>'required',
           'description'=>'nullable',
        ];
    }
    public function withValidator(Validator $validator)
    {
        $validator->after(function (Validator $validator) {
            LogService::log('海柔请求','valideate',
                json_encode($validator));
            if($validator->errors()->isNotEmpty()){
                $validator->errors()->add('code','422');
                $validator->errors()->add('errMsg', json_encode($validator->errors()->messages(),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
                $validator->errors()->add('data',$validator->errors()->toJson(JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES));
            }
        });
    }
}
