<?php

namespace Functional\Routines\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * Une routine, avec ses exercices ordonnés (chargés via routineExercises.exercise).
 */
class RoutineResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'description' => $this->description,
            'is_public' => $this->is_public,
            'estimated_minutes' => $this->estimated_minutes,
            'exercises' => RoutineExerciseResource::collection($this->whenLoaded('routineExercises')),
        ];
    }
}
