<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserRequest extends FormRequest{
    public function authorize(){
        return true;
    }

    public function rules(){
        if($this->method() == 'PATCH'){
            return [
             
                'email' => 'required|email|unique:users,email,'.$this->id,
                // 'contact_number' => 'required|digits:10|contact_number,'.$this->id,
                'contact_number' => 'required|digits:10',
                'role' => 'required',
               
'pan_no' => [
   
    'regex:/^[a-zA-Z0-9]{10}$/',
    'unique:users,pan_no,'.$this->id,
],
            ];
        }else{
            return [
               
                'email' => 'required|email|unique:users,email',
                // 'contact_number' => 'required|digits:10|contact_number',
                'contact_number' => 'required|digits:10',
                'role' => 'required',
                
                'pan_no' => [
    
    'regex:/^[a-zA-Z0-9]{10}$/',
    'unique:users,pan_no,'.$this->id,
],

            ];
        }
    }

    public function messages(){
        return [
            
     
            'email.required' => 'Please enter email',
            'email.email' => 'Please enter valid email',
            'email.unique' => 'Please enter unique email',
            'contact_number.required' => 'Please enter contact number number',
            'contact_number.digits' => 'Please enter 10 digit number',
            // 'contact_number.unique' => 'Please enter unique contact number',
            'role.required' => 'Please select role',
            'name_of_company' => 'Please enter name of company',
            'pan_no' => 'Please enter unique pan no.'
        ];
    }
}
