<?php

namespace Modules\Mall\Http\Resources\Api\Order;

use App\Api\Resources\BaseCollection;
use Modules\Mall\Http\Resources\Api\Shop\ShopBaseInfoResource;
use Modules\Mall\Models\Order;

class OrderCollection extends BaseCollection
{

    public function toArray($request): array
    {
        return [
            'data' => $this->collection->map(function ($order) {
                return [
                    'order_no'         => $order->order_no,
                    'shop'             => new ShopBaseInfoResource($order->shop),
                    'amount'           => $order->amount,
                    'freight'          => $order->freight,
                    'total'            => $order->total,
                    'type'             => $order->type_text,
                    'state'            => $order->state_text,
                    'can'              => $order->getCanAction(),
                    'is_logistic_show' => $order->is_logistic_show,
                    'created_at'       => (string) $order->created_at,
                    'items'            => OrderItemResource::collection($order->items),
                ];
            }),
            'page' => $this->page(),
        ];
    }

}