<?php

namespace App\Http\Controllers\Api\V1\Product\Resources\Attribute;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ProductAttributeProductShowResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  Request  $request
     * @return array|Arrayable|\JsonSerializable
     */
    public function toArray($request): array
    {
        return [
            'attribute_id' => $this->attribute->id,
            'name' => $this->attribute->name,
            'value' => $this->values->map(fn ($val) => $val->real_value)->first(),
        ];
    }
}
