<?php

namespace Functional\Exercises\Http\Resources;

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

/**
 * Détail complet d'un exercice (GET /api/exercises/{id}), instructions localisées.
 */
class ExerciseResource extends JsonResource
{
    public function __construct($resource, private readonly string $locale)
    {
        parent::__construct($resource);
    }

    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'slug' => $this->slug,
            'category' => $this->category,
            'equipment' => $this->equipment,
            'target' => $this->target,
            'muscle_group' => $this->muscle_group,
            'secondary_muscles' => $this->secondary_muscles ?? [],
            'instructions' => $this->resource->instructionsFor($this->locale),
            'image_url' => $this->image_url,
            'gif_url' => $this->gif_url,
            'attribution' => $this->attribution,
        ];
    }
}
