<?php

namespace App\Domains\FiestaFutbolInfantil\Resources;

use App\Domains\Catalog\Models\CatalogItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/** @mixin CatalogItem */
class EntryResource extends JsonResource
{
    /** @return array<string, mixed> */
    public function toArray(Request $request): array
    {
        $variant = $this->variants->sole();

        return [
            'id' => $this->id,
            'title' => $this->nombre,
            'description' => $this->descripcion,
            'event_date_ids' => $variant->selectedEventDates()->pluck('id')->values(),
            'stock' => $variant->inventory->real_stock,
            'price' => $this->precio,
        ];
    }
}
