<?php

namespace App\Http\Requests\Customer;

use App\Http\Responses\ApiResponse;
use App\Http\Messages\ErrorMessages;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

class AddCustomerRequest 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',
            'last_name' => 'nullable|string|max:255',
            'email' => 'nullable|email|max:255',
            'gender' => 'nullable|in:M,F,other',
            'ci' => 'nullable|string',
            'phone' => 'required',
            'cod_phone' => 'nullable|string|max:10',
            'date_of_birthday' => 'nullable|date',
            'profile_image' => 'nullable|string|max:255',
            'adress' => 'nullable|string|max:255',
            'source_id' => 'nullable|exists:sources,id',
            'contact_method_id' => 'nullable|exists:contact_methods,id',
            'customer_references_id' => 'nullable|exists:customer_references,id',
            'conversation_id'=> 'nullable',
            'type_customer'=> 'nullable|string',
        ];
    }
    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(
            ApiResponse::error(
                ErrorMessages::UNPROCESSABLE_ENTITY,
                $validator->errors(),
                [],
                422
            )
        );
    }
}
