<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'name'          => 'sometimes|string|nullable|max:255',
            'email'         => [
                'sometimes',
                'email',
                'nullable',
                Rule::unique('users', 'email')
                    ->where('type', Auth::user()?->type?->value)
                    ->ignore(Auth::id()),
            ],
            'phone'         => 'sometimes|string|nullable',
            'language'      => 'sometimes|string|nullable',
            'document'      => 'sometimes|string|nullable',
            'avatar'        => 'sometimes|file|image|mimes:jpg,jpeg,png,webp|max:5120',
            'avatar_base64' => 'sometimes|string|nullable',
            'push_notifications_enabled' => 'sometimes|boolean',
        ];
    }
}
