<?php

namespace Modules\Order\Models\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Option\Models\Resources\OptionResource;
use Modules\Product\Models\Resources\ProductResource;
use Modules\Region\Models\Resources\RegionResource;
use Modules\Store\Models\Resources\StoreResource;

class OrderProductResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'count' => $this->count,
            'product_cost' => $this->product_cost,
            'can_refund'=>$this->refunded() ? true : false,
            'product'=>new ProductResource($this->whenLoaded('product')),
            'option'=>new OptionResource($this->whenLoaded('option')),
            'store'=>new StoreResource($this->whenLoaded('store')),
        ];
    }
}
