<?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
    {
        $l = $this->locale;
        $model = $this->resource;

        return [
            'id' => $this->id,
            'name' => $model->localizedName($l),
            'slug' => $this->slug,
            'body_part' => $model::localizeTerm($this->body_part, $l),
            'category' => $model::localizeTerm($this->category, $l),
            'equipment' => $model::localizeTerm($this->equipment, $l),
            'target' => $model::localizeTerm($this->target, $l),
            'muscle_group' => $model::localizeTerm($this->muscle_group, $l),
            'secondary_muscles' => $model::localizeTerms($this->secondary_muscles, $l),
            'instructions' => $model->instructionsFor($l),
            'image_url' => $this->image_url,
            'gif_url' => $this->gif_url,
            'attribution' => $this->attribution,
        ];
    }
}
