<?php

namespace Seka\Vzdelavanie\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

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

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request): array
    {
        return $this->processCollection($request);
    }

    /**
     * Send fields to hide to UsersResource while processing the collection.
     *
     * @param $request
     * @return array
     */
    protected function processCollection($request): array
    {
        return $this->collection->map(function (SekciaResource $resource) use ($request) {
            return $resource->hide($this->withoutFields)->toArray($request);
        })->all();
    }
}
