<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ProfileUpdateRequest 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 [
            'name'              => 'required|string|max:255|regex:/^[A-Za-z][A-Za-z0-9\s._-]*$/',
            'phone_no'          => 'nullable|string|min:8|max:13|regex:/^[0-9+\-\s\(\)]+$/',
            'email'             => [
                'required',
                'string',
                'email',
                'max:255',
                'unique:users,email,' . auth()->id(),
                'regex:/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/',
            ],
            'whatsapp_number'   => 'nullable|string|regex:/^\+?[0-9\s\-\(\)]+$/|max:20',
            'address'           => 'nullable|string|max:500',
            'latitude'          => 'nullable|numeric|between:-90,90',
            'longitude'         => 'nullable|numeric|between:-180,180',
            'profile_photo'     => 'nullable|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ];
    }
    /**
     * Validation message show
     */
    public function messages(): array
    {
        return [
            'name.required'             => 'Your name is required.',
            'name.string'               => 'The name must be a valid string.',
            'name.max'                  => 'The name may not exceed 255 characters.',
            'name.regex'                => 'The name can only contain letters, numbers, spaces, dots, underscores, or hyphens, and must start with a letter.',

            'phone_no.string'           => 'Phone number must be a valid string.',
            'phone_no.phone'            => 'Phone number format is invalid.',
            'phone_no.max'              => 'Phone number may not exceed 13 characters.',

            'email.required'            => 'Email address is required.',
            'email.string'              => 'Email must be a valid string.',
            'email.email'               => 'Please enter a valid email address.',
            'email.max'                 => 'Email may not exceed 255 characters.',
            'email.unique'              => 'This email address is already in use.',
            'email.regex'               => 'Email format is invalid.',

            'whatsapp_number.string'    => 'WhatsApp number must be a valid string.',
            'whatsapp_number.phone'     => 'WhatsApp number format is invalid.',
            'whatsapp_number.max'       => 'WhatsApp number may not exceed 20 characters.',

            'address.string'            => 'Address must be a valid string.',
            'address.max'               => 'Address may not exceed 500 characters.',

            'latitude.numeric'          => 'Latitude must be a number.',
            'latitude.between'          => 'Latitude must be between -90 and 90.',

            'longitude.numeric'         => 'Longitude must be a number.',
            'longitude.between'         => 'Longitude must be between -180 and 180.',

            'profile_photo.image'       => 'Profile photo must be an image.',
            'profile_photo.mimes'       => 'Profile photo must be a file of type: jpeg, png, jpg, gif, svg.',
            'profile_photo.max'         => 'Profile photo may not exceed 2MB.',
        ];
    }

}
