<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;

class OrderListResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
            'id'=>$this->id,
            'address'=>$this->address,
            'amount'=>'$'.$this->amount,
            'created_at'=>$this->created_at !=null ? $this->created_at->toDayDateTimeString():null,
            'date_time'=>$this->date_time !=null ? Carbon::create($this->date_time)->toDayDateTimeString():null,
            'description'=>$this->description,
            'email'=>$this->email,
            'latitude'=>$this->latitude,
            'longitude'=>$this->longitude,
            'name'=>$this->name,
            'payment_status'=>$this->payment_status=='COMPLETED' ? 'COMPLETED': 'Not Completed',
            'phone'=>$this->phone,
            'photo'=>$this->photo != null ? url('Image/Order').'/'.$this->photo :null,
            'service_status'=>$this->service_status == 1 ?'Pending':'Completed',
            'assignedBy'=>$this->assignedBy != null? new AssignedByResource($this->assignedBy):null ,
            'assignedTo'=>$this->assignedTo != null? new AssignedToResource($this->assignedTo):null ,
            'serviceData'=>$this->serviceData != null? new ServiceResource($this->serviceData):null ,
            'user'=>$this->user != null? new UserResource($this->user):null ,
        ];
    }
}
