<?php

namespace Modules\Travel\Transformers;

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

class TravelExpenseResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id'                        => $this->id,
            'travel_plan_id'            => $this->travel_plan_id,
            'employee'                  => [
                                            'id'          => $this->employee_id,
                                            'name'        => @$this->employee->name,
                                            'department'  => @$this->employee->department->title,
                                            'designation' => @$this->employee->designation->title,
                                            'avatar'      => uploaded_asset(@$this->employee->avatar_id),
                                        ],
            'date'                      => $this->date,
            'mode_of_transportation'    => $this->mode_of_transportation,
            'total_amount'              => $this->total_amount,
            'approval_amount'           => $this->approval_amount,
            'status'                    => @$this->status->name,
            'rating'                    => $this->rating_of_travel_experience,
            'approve'                   => [
                                            'approved_by' => @$this->approvedBy->name,
                                            'approved_at' => $this->approved_at ? Carbon::parse($this->approved_at)->format('Y-m-d h:i A') : null,
                                        ],
        ];
    }
}
