<?php

namespace App\Http\Resources\Support;

use Illuminate\Http\Resources\Json\ResourceCollection;

class SupportRequestCollection extends ResourceCollection
{
    public function toArray($request): array
    {
        return $this->collection->map(function ($item) use ($request) {
            return (new SupportRequestResource($item))->toArray($request);
        })->all();
    }

    public function with($request): array
    {
        if (!method_exists($this->resource, 'total')) {
            return [];
        }

        return [
            'meta' => [
                'total' => $this->resource->total() ?? null,
                'per_page' => $this->resource->perPage() ?? null,
                'current_page' => $this->resource->currentPage() ?? null,
                'last_page' => $this->resource->lastPage() ?? null,
            ],
        ];
    }
}
