<?php

namespace App\Http\Requests\Guest;

use App\Support\PhoneNumber;
use Illuminate\Foundation\Http\FormRequest;

class LoginGuestRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    protected function prepareForValidation(): void
    {
        $this->merge([
            'phone' => PhoneNumber::normalize($this->input('phone')),
        ]);
    }

    public function rules(): array
    {
        return [
            'phone' => PhoneNumber::rules(true),
            'password' => ['required', 'string', 'min:6', 'max:255'],
        ];
    }

    public function messages(): array
    {
        return [
            'phone.required' => 'Введите телефон.',
            'phone.regex' => PhoneNumber::VALIDATION_MESSAGE,
            'password.min' => 'Пароль должен быть не менее 6 знаков.',
        ];
    }
}
