<?php

namespace App\Http\Requests\Auth;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Password;

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

    public function rules(): array
    {
        return [
            'name'                    => ['required', 'string', 'max:255'],
            'email'                   => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password'                => ['required', 'confirmed', Password::min(8)->letters()->numbers()],
            'date_of_birth'           => ['required', 'date', 'before:-18 years'],
            'phone'                   => ['nullable', 'string', 'max:30'],
            'email_marketing_consent' => ['boolean'],
        ];
    }

    public function messages(): array
    {
        return [
            'date_of_birth.before' => 'You must be at least 18 years old to register.',
        ];
    }
}
