<?php

namespace Functional\Tracking\Http\Resources;

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

/**
 * Une séance d'entraînement, avec ses séries (setLogs) quand elles sont chargées.
 */
class WorkoutSessionResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'routine_id' => $this->routine_id,
            'status' => $this->status->value,
            'started_at' => $this->started_at,
            'ended_at' => $this->ended_at,
            'total_volume' => $this->total_volume,
            'notes' => $this->notes,
            'set_count' => $this->when($this->set_logs_count !== null, $this->set_logs_count),
            'set_logs' => SetLogResource::collection($this->whenLoaded('setLogs')),
        ];
    }
}
