<?php

namespace Modules\Order\Models\Resources;

use Modules\User\Models\Resources\UserResource;
use Modules\User\Models\Resources\AddressResource;
use Modules\Coupon\Models\Resources\CouponResource;
use Modules\Store\Models\Resources\StoreResource;
use Modules\Store\Models\Resources\BranchResource;
use Illuminate\Http\Resources\Json\JsonResource;

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,
            'payment_status'=>$this->payment_status,
            'discount'=>number_format($this->discount,2, '.', ''),
            'total_tax'=>number_format($this->total_tax,2, '.', ''),
            'shipping_cost'=>number_format($this->shipping_cost,2, '.', ''),
            'on_hand_cost'=>number_format($this->on_hand_cost,2, '.', ''),
            'total_products'=>number_format($this->total_products,2, '.', ''),
            'total'=>number_format($this->total,2, '.', ''),
            'user' =>new UserResource($this->whenLoaded('user')),
            'coupon' =>new CouponResource($this->whenLoaded('coupon')),
            'address' =>new AddressResource($this->whenLoaded('address')),
            'store' =>new StoreResource($this->whenLoaded('store')),
            'branch' =>new BranchResource($this->whenLoaded('branch')),
            'products' =>OrderProductResource::collection($this->whenLoaded('products')),
      ];
    }
}
