<?php

namespace App\Http\Resources\Models;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ItemProtoRefineResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $maxItems = 5;

        return [
            'items' => collect(range(0, $maxItems - 1))
                ->filter(fn ($index) => $this->{"item$index"})
                ->map(fn ($index) => [
                    'vnum' => $this->{"item$index"}->vnum,
                    'name' => $this->{"item$index"}->locale_name,
                    'count' => $this->{"count$index"},
                ]),
            'cost' => $this->cost,
            'probability' => $this->prob,
        ];
    }
}
