<?php

namespace App\Api\Resources\Order;

use App\Api\Resources\BaseCollection;
use App\Api\Resources\User\UserBaseResource;
use Modules\Mall\Http\Resources\Api\Order\OrderExpressResource;

class OrderDataCollection extends BaseCollection
{

    public function toArray($request): array
    {
        return [
            'data' => $this->collection->map(function ($order) {
                return [
                    'order_no' => $order->order_no,
                    'user'     => new UserBaseResource($order->user),
                    'express'  => new OrderExpressResource($order->express),
                    'qty'      => $order->items()->sum('qty'),
                    'amount'   => $order->amount,
                    'freight'  => $order->freight,
                    'total'    => $order->total,
                    'type'     => $order->type_text,
                    'state'    => $order->state_text,
                ];
            }),
            'page' => $this->page(),
        ];
    }

}