<?php

namespace TPS\Birzha\Classes;

use Illuminate\Http\Resources\Json\JsonResource;
 
class ProductResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name_ru' => $this->getAttributeTranslated('name', 'ru'),
            'name_en' => $this->getAttributeTranslated('name', 'en'),
            'name_tm' => $this->getAttributeTranslated('name', 'tm'),
            'category_id' => $this->categories()->first()->id,
            'productForEditing' => $this->id,
            'quantity' => $this->quantity,
            'price' => $this->price,
            'place' => $this->place,
            'description_tm' => $this->getAttributeTranslated('description', 'tm'),
            'description_en' => $this->getAttributeTranslated('description', 'en'),
            'description_ru' => $this->getAttributeTranslated('description', 'ru'),
            'payment_term_id' => $this->payment_term ? $this->payment_term->id : null,
            'packaging' => $this->packaging,
            'delivery_term_id' => $this->delivery_term ? $this->delivery_term->id : null,
            'currency_id' => $this->currency ? $this->currency->id : null,
            'measure_id' => $this->measure ? $this->measure->id : null,
            'old_img' => ImageResource::collection($this->images)
        ];
    }
}