<?php

namespace App\Http\Resources\Company;

use Illuminate\Http\Resources\Json\JsonResource;

class LoanDeniedRequestDetails 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,
            'worker_id' => $this->worker_id,
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'rate' => $this->rate,
            'original_rate' => $this->original_rate,
            'date_requested' => $this->date_requested,
            'date_from' => $this->date_from,
            'date_to' => $this->date_to,
            'requester_note' => $this->requester_note,
            'declined_date' => $this->declined_date,
            'declined_by' => $this->declined_by($this->approver_first_name, $this->approver_last_name),
            'approver_note' => $this->approver_note,
        ];
    }

    public function declined_by($approver_first_name, $approver_last_name) {
        if (empty($approver_first_name)) {
            return 'System';
        }
        
        return $approver_first_name.' '.$approver_last_name;
    }
}
