<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'name' => ['sometimes', 'string', 'max:255'],
            'bio' => ['sometimes', 'nullable', 'string'],
            'height' => ['sometimes', 'nullable', 'integer'],
            'avatar' => ['sometimes', 'nullable', 'image', 'max:2048'],
            'nutritionGoals' => ['sometimes', 'array'],
            'nutritionGoals.calories' => ['required_with:nutritionGoals', 'integer', 'min:0', 'max:100000'],
            'nutritionGoals.proteins' => ['required_with:nutritionGoals', 'numeric', 'min:0', 'max:10000'],
            'nutritionGoals.carbs' => ['required_with:nutritionGoals', 'numeric', 'min:0', 'max:10000'],
            'nutritionGoals.fats' => ['required_with:nutritionGoals', 'numeric', 'min:0', 'max:10000'],
        ];
    }

    public function messages(): array
    {
        return [
            'avatar.max' => "L'image ne doit pas dépasser 2 Mo.",
            'nutritionGoals.calories.integer' => 'Les calories doivent etre un nombre entier.',
            'nutritionGoals.*.required_with' => 'Renseigne tous les objectifs nutritionnels.',
            'nutritionGoals.*.min' => 'Les objectifs nutritionnels doivent etre positifs.',
            'nutritionGoals.*.max' => 'La valeur de cet objectif nutritionnel est trop elevee.',
        ];
    }
}
