<?php

namespace App\Http\Resources;

use App\Models\Rating;
use Illuminate\Http\Resources\Json\JsonResource;

class ProductResource 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 [
            'id'                         => $this->id,
            'title'                      => $this->title,
            'price'                      => $this->price,
            'storeowner_id'              => $this->storeowner_id,
            'storeowner'                 => optional($this->storeowner)->name,
            'store_detail_id'                   => $this->store_detail_id,
            'store_name'                 => optional($this->store)->store_name,
            'category_id'                => $this->category_id,
            'category'                   => optional($this->category)->name,
            'subcategory_id'             => $this->subcategory_id,
            'subcategory'                => optional($this->subcategory)->name,
            'storetype_id'               => $this->storetype_id,
            'storetype'                  => optional($this->storetype)->name,
            'status'                     => $this->status,
            'description'                => $this->description,
            'product_image'              => getSingleMedia($this, 'product_image',null),
            'created_at'                 => $this->created_at,
            'updated_at'                 => $this->updated_at,
            'deleted_at'                 => $this->deleted_at,
        ];
    }
}
