<?php

namespace App\Http\Requests\UserProfile;

use App\Rules\User\VerifyCurrentPasswordBeDeferentWithPasswordRule;
use App\Rules\User\VerifyCurrentPasswordRule;
use Illuminate\Foundation\Http\FormRequest;

class ChangePasswordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'current_password' => ['required', new VerifyCurrentPasswordRule()],
            'password' => ['required', 'min:8', 'regex:#.*^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$#', new VerifyCurrentPasswordBeDeferentWithPasswordRule()],
            'confirm' => 'required|same:password' ,
        ];
    }

    public function messages()
    {
        return [
            'password.regex' => 'Passwords must contain at least eight characters, including uppercase, lowercase letters, numbers and symbol',
            'confirm.same' => 'Confirm passowrd not match'
        ];
    }

}
