<?php

namespace Modules\ChipOrder\Resources\Api;

use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Address\Resources\Api\AddressResource;
use Modules\User\Resources\Api\UserResource;

class ChipOrderResource extends JsonResource
{

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => (int) $this->id,
            'total' => (double) $this->total,
            'tax_cost' => (double) $this->tax_cost,
            'shipping_cost' => (double) $this->shipping_cost,
            'date' => $this->getDateAttribute(),
            'user' => new UserResource($this->user),
            'address' => new AddressResource($this->address),
            'status' => (int) $this->status,
            'status_text' => __('chipOrders.status_' . $this->status),
            'details' => ChipOrderDetailsResource::collection($this->products)
        ];
    }

}
