<?php

namespace Seka\Vzdelavanie\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

/**
 * Class KategoriaResource
 * @package Seka\Vzdelavanie\Http\Resources
 */
class KategoriaResource extends JsonResource
{
    use HideResourceFieldsTrait;

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return $this->filterFields([
            'id' => $this->hash_id,
            'nazov' => $this->nazov,
            'obrazok' => $this->obrazok,
            'datum_vytvorenia' => (string) $this->created_at,
            'datum_zmeny' => (string) $this->updated_at,
            'ucebnice_count' => (int) $this->ucebnice_count,
            'ucebnice' => $this->whenLoaded('ucebnice', function () {
                return UcebnicaResource::collection($this->resource->ucebnice);
            }),
        ]);
    }
}
