<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

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

        $data = TestResource::collection($this->whenLoaded('testSamples'));

        return [
            'id' => $this->id,
            'department_id' => $this->department_id,
            'name_en' => $this->name_en,
            'tube' => (string)$this->tube,
            'descriptions' => json_decode($this->description),
            'bg_color' => $this->bg_color,
            'color' => $this->color,
            'testSamples' => TestResource::collection($this->whenLoaded('testSamples')),
        ];
    }
}
