<?php

namespace Modules\SystemCore\App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateContactRequest 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.
     */
    public function rules(): array
    {
        return [
            'contact_type' => [
                'nullable',
                'string',
                'in:primary,billing,technical,sales,support,other',
            ],
            'first_name' => [
                'required',
                'string',
                'max:100',
            ],
            'last_name' => [
                'nullable',
                'string',
                'max:100',
            ],
            'job_title' => [
                'nullable',
                'string',
                'max:100',
            ],
            'department' => [
                'nullable',
                'string',
                'max:100',
            ],
            'email' => [
                'nullable',
                'email',
                'max:255',
            ],
            'phone' => [
                'nullable',
                'string',
                'max:50',
            ],
            'mobile' => [
                'nullable',
                'string',
                'max:50',
            ],
            'is_primary' => [
                'boolean',
            ],
        ];
    }

    /**
     * Get custom messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'contact_type.in' => __('Invalid contact type.'),
            'first_name.required' => __('First name is required.'),
            'first_name.max' => __('First name cannot exceed :max characters.'),
            'last_name.max' => __('Last name cannot exceed :max characters.'),
            'job_title.max' => __('Job title cannot exceed :max characters.'),
            'department.max' => __('Department cannot exceed :max characters.'),
            'email.email' => __('Please enter a valid email address.'),
            'email.max' => __('Email cannot exceed :max characters.'),
            'phone.max' => __('Phone number cannot exceed :max characters.'),
            'mobile.max' => __('Mobile number cannot exceed :max characters.'),
        ];
    }

    /**
     * Get custom attributes for validator errors.
     */
    public function attributes(): array
    {
        return [
            'contact_type' => __('contact type'),
            'first_name' => __('first name'),
            'last_name' => __('last name'),
            'job_title' => __('job title'),
            'department' => __('department'),
            'email' => __('email'),
            'phone' => __('phone'),
            'mobile' => __('mobile'),
            'is_primary' => __('primary'),
        ];
    }
}
