<?php

namespace Gisplus\Package\EstatechVendor\Requests;

use Illuminate\Foundation\Http\FormRequest;

use App\Rules\ExistRule;

use App\Rules\UpdateUniqueRule;

class VendorRequest 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()
    {
        // parent::errorMessage('Required form validation.');

        $current_path = url()->current();

       if($current_path === url('vendorupdate'))
        {

            $validation['cnic'] = ['nullable', 'max:15', new UpdateUniqueRule('users', 'cnic', $this->user_id)];
          
            return $validation;

        }
        elseif($current_path === url('vendorcommit'))
        {
            return  $this->getValidationList();

        }
    
    }

    public function getValidationList()
    {
     
        $validation = $this->input();

        return [
            
            'full_name'         =>  'required|min:3|max:50',
            'cnic'              =>  'nullable|max:15|unique:users',
            'contact'           =>  'required|min:0|max:60',
            'temporary_address' =>  'nullable|min:0|max:255',
            'permanent_address' =>  'nullable|min:0|max:255',
            'ntn'               =>   'nullable|min:0|max:25',   
            'stn'               =>   'nullable|min:0|max:25',
            'user_image'        =>  'nullable|image:jpeg,png,jpg|max:250',

  

        ];
    }
}
