<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ContactFormRequest extends FormRequest
{
    /**
     * 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<string, mixed>
     */
    public function rules()
    {
        return [
            'first_name' => 'required|string|max:255',
            'last_name'  => 'required|string|max:255',
            'email'      => 'required|email|max:255',
            'phone' =>     ['required', 'string', 'max:15', 'regex:/^\+?[0-9\- ]+$/'],  // Allows numbers, dashes, spaces, and optional '+'
            'message'    => 'required|string|max:500',
        ];
    }

    public function messages()
    {
        return [
            'first_name.required' => 'First Name is required',
            'last_name.required'  => 'Last Name is required',
            'email.required'      => 'Email is required',
            'email.email'         => 'Please enter a valid email',
            'phone.required'      => 'Phone number is required',
            'phone.regex'         => 'Please enter a valid phone number (only digits, spaces, and dashes are allowed)',
            'message.required'    => 'Message is required',
        ];
    }
}
