<?php

namespace App\Http\Requests;


use App\Rules\PasswordValidationRule;

class UserEditRequest extends BaseRequest
{

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $userData =  [
            'first_name'=>'required',
            'last_name'=>'required',
            'email'=>'required|email',
            'previous_email'=>'required|email',
            'street_no'=>'required|regex:'.$this->script_validation_rule,
            'street_name'=>'required|regex:'.$this->script_validation_rule,
            'city'=>'required|regex:'.$this->script_validation_rule,
            'state'=>'required|regex:'.$this->script_validation_rule,
            'zip_code'=>'required|regex:'.$this->script_validation_rule,
            'phone'=>'required|regex:'.$this->script_validation_rule,
            'password'=> ['required','min:8'],
//            'reset_account'=>'sometimes',
        ];
        $inputData = request()->all();

        if(isset($inputData['report_provider_info']) && $inputData['report_provider_info']) {
            $userData['source_type'] = 'required';
            $userData['birth_date'] = 'required|date_format:m/d/Y|before:18 years ago|after:-150 years';
            $userData['ssn'] = 'required|min:4|max:4';
        }
        if($inputData['previous_email'] != $inputData['email']){

            $userData['email'] = 'required|email|unique:users,email';

        }

         return $userData;
    }

    public function messages()
    {
        return [
            'password.min' => 'Password mast be 8 characters.',
        ];
    }
}
