<?php

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

use Illuminate\Http\Resources\Json\JsonResource;

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