<?php

namespace App\Http\Resources\Hrm\Attendance;

use App\Helpers\CoreApp\Traits\TimeDurationTrait;
use Illuminate\Http\Resources\Json\ResourceCollection;

class BreakBackCollection extends ResourceCollection
{
    use TimeDurationTrait;

    public function toArray($request)
    {
        return [
            'today_history' => $this->collection->map(function ($data) {
                return [
                    'name' => @$data->user->name,
                    'reason' => $data->reason,
                    'break_time_duration' => $this->hourOrMinute($data->start_time, $data->end_time),
                    'break_back_time' => $this->dateTimeInAmPm($data->start_time,) . ' To ' . $this->dateTimeInAmPm($data->end_time),
                ];
            }),
            'links' => [
                "first" => \request()->url() . "?page=1",
                "last" => \request()->url() . "?page=1",
                "prev" => null,
                "next" => null
            ],
            'pagination' => [
                'total' => $this->total(),
                'count' => $this->count(),
                'per_page' => $this->perPage(),
                'current_page' => $this->currentPage(),
                'total_pages' => $this->lastPage()
            ],
        ];
    }
}
