<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'registration_number' => ['required', 'string', 'max:8', 'regex:/^(?=.*\d)[A-Za-z0-9 ]+$/'],
            'contact_data' => ['required', 'array'],
            'contact_data.name' => ['nullable', 'string', 'max:255'],
            'contact_data.email' => ['required_without:contact_data.phone', 'nullable', 'email', 'max:255'],
            'contact_data.phone' => ['required_without:contact_data.email', 'nullable', 'string', 'max:50'],
            'contact_data.address' => ['nullable', 'string', 'max:500'],
            'contact_data.message' => ['nullable', 'string', 'max:2000'],
        ];
    }

    public function messages(): array
    {
        return [
            'registration_number.required' => 'Vehicle registration number is required',
            'registration_number.max' => 'Vehicle registration number must not exceed 8 characters',
            'registration_number.regex' => 'Invalid registration number format',
            'contact_data.required' => 'Contact data is required',
            'contact_data.array' => 'Contact data must be a valid object',
            'contact_data.email.required_without' => 'Please provide at least an email address or phone number',
            'contact_data.email.email' => 'Please provide a valid email address',
            'contact_data.phone.required_without' => 'Please provide at least a phone number or email address',
        ];
    }
}
