<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ProductResource extends JsonResource
{
    public function toArray($request)
    {
        return [

            'id'=>$this->id,

            'category_id'=>$this->category_id,

            'category'=>$this->category?->category_name,

            'product_name'=>$this->product_name,

            'product_code'=>$this->product_code,

            'description'=>$this->description,

            'price'=>$this->price,

            'discount_price'=>$this->discount_price,
            
            'stock_quantity' => $this->stock_quantity,

            'unit'=>$this->unit,

            'product_image'=>$this->product_image
                ? asset('storage/'.$this->product_image)
                : null,

            'status'=>$this->status,

            'display_order'=>$this->display_order,

            'created_at'=>$this->created_at?->format('d-m-Y H:i')

        ];
    }
}