<?php

namespace App\Http\Requests;


use App\Rules\PasswordValidationRule;
use Illuminate\Validation\Rule;

class ClientRegistration extends BaseRequest
{

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $userData = [
            'first_name'=>'required|string',
            'last_name'=>'required|string',
            'email'=>'required|email|unique:users,email',
            'password'=>['required','min:8', new PasswordValidationRule()],

            'street_no'=>'required|string|max:5|regex:'.$this->street_validation_rule,
            'street_name'=>'required|max:50|regex:'.$this->street_validation_rule,
            'city'=>'required|string|regex:'.$this->script_validation_rule,
            'state'=>'required|string|regex:'.$this->script_validation_rule,
            'zip_code'=>'required|string|min:5|max:5|regex:'.$this->script_validation_rule,
            'phone'=>'required|string|regex:'.$this->script_validation_rule,
            'user_access_date'=> 'date_format:m/d/Y|after:today'
        ];

        $inputData = request()->all();

        if(isset($inputData['make_payment']) && $inputData['make_payment']) {
            $userData['payment_date'] = 'required|date_format:m/d/Y|before:tomorrow';
            $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';
            $userData['card_number'] = 'required';
            $userData['expiry'] = 'required';
            $userData['make_payment'] = 'required';
            $userData['user_access_date'] = '';
        }

       return $userData;

    }
}
