<?php

declare(strict_types=1);

namespace App\Http\Resources\Wiki\Collection;

use App\Http\Resources\BaseCollection;
use App\Http\Resources\Wiki\Resource\ExternalResourceJsonResource;
use App\Models\Wiki\ExternalResource;
use Illuminate\Http\Request;

class ExternalResourceCollection extends BaseCollection
{
    /**
     * The "data" wrapper that should be applied.
     *
     * @var string|null
     */
    public static $wrap = 'resources';

    /**
     * Transform the resource into a JSON array.
     *
     *
     * @noinspection PhpMissingParentCallCommonInspection
     */
    public function toArray(Request $request): array
    {
        return $this->collection->map(
            fn (ExternalResource $resource): ExternalResourceJsonResource => new ExternalResourceJsonResource($resource, $this->query)
        )->all();
    }
}
