<?php

namespace Modules\Travel\Transformers;

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

class TravelMeetingResource 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,
            'meeting_schedule_time' => Carbon::parse($this->meeting_schedule_time)->format('h:i A'),
            'meeting_start_time'    => Carbon::parse($this->meeting_start_time)->format('h:i A'),
            'meeting_end_time'      => Carbon::parse($this->meeting_end_time)->format('h:i A'),
            'total_meeting_time'    => calculateTotalHoursHumanReadable($this->meeting_start_time, $this->meeting_end_time),
            'customer_company_name' => $this->customer_company_name,
            'customer_name'         => $this->customer_name,
            'customer_email'        => $this->customer_email,
            'customer_phone'        => $this->customer_phone,
            'purpose'               => $this->purpose,
            'remark'                => $this->remark,
            'file'                  => $this->file_id ? uploaded_asset($this->file_id) : null,
            'rating'                => $this->rating_of_meeting_experience,
        ];
    }
}
