<?php

namespace Modules\Travel\Transformers;

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

class TravelWorkflowResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id'                            => $this->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,
            'start_time'                    => Carbon::parse($this->start_time)->format('h:i A'),
            'end_time'                      => Carbon::parse($this->end_time)->format('h:i A'),
            'total_time'                    => calculateTotalHoursHumanReadable($this->start_time, $this->end_time),
            'calls_made'                    => $this->calls_made,
            'positive_leads'                => $this->positive_leads,
            'total_sales'                   => $this->total_sales,
            'is_update_pending_and_leads'   => $this->is_update_pending_and_leads,
            'pending_and_leads_other_note'  => $this->pending_and_leads_other_note,
            'is_worked_on_recovery_today'   => $this->is_worked_on_recovery_today,
            'recovery_today_other_note'     => $this->recovery_today_other_note,
            'daily_report_summary'          => $this->daily_report_summary,
            'complaints_questions_comments' => $this->complaints_questions_comments,
            'file'                          => $this->file_id ? uploaded_asset($this->file_id) : null,
            'how_was_your_day_mark'         => $this->how_was_your_day_mark,
        ];
    }
}
