<?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 OfflineOrderRequest 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',
//            'mobile'=>'required|mobile',
//            'contract_no'=>'required|unique:partner_offline_orders,contract_no',
            'pay_type'=>'nullable|in:1,2,3',
            'bank_name'=>'nullable',
            'bank_num'=>'nullable',
            'price'=>'nullable'
        ];
    }

    public function messages()
    {
        return [
            'name.required'=>'请填写姓名',
            // 'name.name'=>'姓名格式错误',
            'mobile.required'=>'请填写手机号',
//            'mobile.mobile'=>'手机号格式错误',
//            'contract_no.required'=>'请填写合同编号',
//            'contract_no.unique'=>'合同编号已存在',
        ];
    }

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