<?php

namespace App\Http\Resources\Api\Dashboard\Admin\Workout;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\Api\Dashboard\Admin\WorkoutCategory\WorkoutCategoryResource;

class WorkoutResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $locales = [];

        foreach (config('translatable.locales') as $locale) {
            $locales[$locale]['title']        = @$this->translate($locale)?->title;
            $locales[$locale]['desc']         = @$this->translate($locale)?->desc;
        }
        return [
            'id'                 => $this->id,
            'title'              => $this->title,
            'desc'               => $this->desc,
            'video'              => $this->video,
            'image'              => $this->image,
            'workout_category'   => WorkoutCategoryResource::make($this->category),
        ] + $locales;
    }
}
