<?php

namespace App\Http\Resources\Product;

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

class ProductVariantResource 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,
            'is_product_variant' => $this->is_product_variant,
            'selling_price' => $this->inventory->selling_price,
            'stock_type' => $this->inventory->stock_type,
            'stock' => $this->inventory->stock,
            'total_sold' => $this->total_sold,
            'reviews' => ProductReviewResource::collection($this->whenLoaded('reviews'))
        ];
    }
}
