<?php

namespace App\Http\Resources\Product;

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

class ProductInfoResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->uuid,
            'server_image_url' => $this->server_image_url,
            'name' => $this->name,
            'has_variant' => $this->has_variant,
            'description' => $this->description,
            'unit' => $this->unit->name,
            'variants' => ProductVariantResource::collection($this->whenLoaded('variants')),
        ];
    }
}
