<?php

namespace Modules\Order\Models\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Coupon\Models\Resources\CouponResource;
use Modules\Option\Models\Resources\OptionResource;
use Modules\PaymentWay\Models\Resources\PaymentWayResource;
use Modules\Product\Models\Resources\ProductResource;
use Modules\Region\Models\Resources\RegionResource;
use Modules\Store\Models\Resources\StoreResource;
use Modules\User\Models\Resources\AddressResource;

class OrderResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'payment_id'=>$this->payment_id,
            'status'=>$this->status,
            'total_tax'=>$this->total_tax,
            'shipping_cost'=>$this->shipping_cost,
            'on_hand_cost'=>$this->on_hand_cost,
            'total_products'=>$this->total_products,
            'discount'=>$this->discount,
            'discount_offer'=>$this->discount_offer,
            'total'=>$this->total,
            'note'=>$this->note,
            'qr_image'=>$this->qr_image,
            'date'=>date('Y-m-d g:i a',strtotime($this->created_at)),
            'products'=>OrderProductResource::collection($this->whenLoaded('products')),
            'tracks'=>OrderTrackResource::collection($this->whenLoaded('tracks')),
            'address'=>new AddressResource($this->whenLoaded('address')),
            'paymentWay'=>new PaymentWayResource($this->whenLoaded('way')),
            'coupon'=>new CouponResource($this->whenLoaded('coupon')),
        ];
    }
}
