<?php

namespace Functional\Users\Http\Requests;

use Functional\Users\Enums\Units;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * Mise à jour du profil courant (PATCH /api/me) : préférences + matériel possédé.
 * Tous les champs sont optionnels (mise à jour partielle).
 */
class UpdateProfileRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() !== null;
    }

    /**
     * @return array<string, ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'locale' => ['sometimes', 'string', Rule::in(['fr', 'en', 'pt-BR'])],
            'units' => ['sometimes', Rule::enum(Units::class)],
            'timezone' => ['sometimes', 'nullable', 'string', 'max:64'],
            'available_equipment' => ['sometimes', 'array'],
            'available_equipment.*' => ['string', 'max:64'],
        ];
    }
}
