<?php

namespace App\Http\Requests;

use App\Libs\Security\XSSCleanFilter;
use Illuminate\Validation\Rule;
use Waavi\Sanitizer\Laravel\SanitizesInput;

class UserRegister extends BaseFormRequest
{
    use SanitizesInput;

    /**
     * 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()
    {
        return [
            'name' => 'required|max:150',
            'email' => [
                'required',
                'max:150',
                'email',
                Rule::unique('users')->where(function ($query) {
                    return $query->where('active', true);
                })
            ],
            'password' => 'required|'.config('auth.password_validation_rule').'|confirmed'
        ];
    }

    /**
     * Filters to be applied to the input.
     *
     * @return array
     */
    public function filters()
    {
        return [
            'name' => "trim|strip_tags|xss_clean"
        ];
    }

    public function customFilters()
    {
        return ['xss_clean' => XSSCleanFilter::class];
    }
}
