<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class DocumentsCollection extends ResourceCollection
{
    private $nextKey = FALSE;

    /**
     * Create a new resource instance.
     *
     * @param  mixed  $resource
     * @return void
     */
    public function __construct($resource, $nextKey = FALSE)
    {
        parent::__construct($resource);

        $this->resource = $this->collectResource($resource);
        $this->nextKey = $nextKey;
    }

    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $out = [
            'data' => $this->collection,
            'nextKey' => null
        ];

        if($this->nextKey) {
            $out['nextKey'] = $this->nextKey;
        }
        return $out;
    }
}
