<?php

namespace Functional\Routines\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

/**
 * Validation de la mise à jour d'une routine. Les exercices, si fournis, remplacent
 * intégralement le pivot routine_exercises existant.
 */
class UpdateRoutineRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'name' => ['sometimes', 'string', 'max:255'],
            'description' => ['nullable', 'string'],
            'is_public' => ['sometimes', 'boolean'],
            'estimated_minutes' => ['nullable', 'integer', 'min:1'],
            'exercises' => ['sometimes', 'array'],
            'exercises.*.exercise_id' => ['required', 'integer', 'exists:exercises,id'],
            'exercises.*.position' => ['nullable', 'integer', 'min:0'],
            'exercises.*.sets' => ['required', 'integer', 'min:1'],
            'exercises.*.target_reps' => ['required', 'string', 'max:50'],
            'exercises.*.rest_seconds' => ['nullable', 'integer', 'min:0'],
            'exercises.*.tempo' => ['nullable', 'string', 'max:50'],
            'exercises.*.target_weight' => ['nullable', 'numeric', 'min:0'],
            'exercises.*.notes' => ['nullable', 'string'],
        ];
    }
}
