<?php

namespace Modules\Refund\Models\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Option\Models\Resources\OptionResource;
use Modules\Order\Models\Resources\OrderProductResource;
use Modules\Order\Models\Resources\OrderResource;
use Modules\Product\Models\Resources\ProductResource;
use Modules\Reason\Models\Resources\ReasonResource;
use Modules\Region\Models\Resources\RegionResource;
use Modules\User\Models\Resources\AddressResource;
use Modules\User\Models\Resources\PaymentCardResource;

class RefundResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'uuid'=>$this->uuid,
            'status'=>$this->status,
            'image'=>$this->image ? asset($this->image) : null,
            'note'=>$this->note,
            'date'=>date('Y-m-d g:i a',strtotime($this->created_at)),
            'statuses'=>RefundStatusResource::collection($this->whenLoaded('statuses')),
            'reason'=>new ReasonResource($this->whenLoaded('reason')),
            'card'=>new PaymentCardResource($this->whenLoaded('card')),
            'address'=>new AddressResource($this->whenLoaded('address')),
            'product'=>new OrderProductResource($this->whenLoaded('product')),
            'order'=>new OrderResource($this->whenLoaded('order')),
        ];
    }
}
