<?php

namespace App\Http\Resources;

use App\CaseTopic;
use App\CompanyRequestTopic;
use App\Helpers\ImageHelper;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @property mixed files
 * @property mixed company_request_topic_id
 */
class CompanyRequestResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $files = array_map(function ($value){
            return ImageHelper::getFullPath($value);
        }, $this->files);

        $companyRequestTopic = CompanyRequestTopic::find($this->company_request_topic_id);

        return [
            'id' => $this->id,
            'request_no' => $this->id,
            'user_name' => $this->name,
            'user_email' => $this->email,
            'user_phone' => $this->phone,
            'topic' => $companyRequestTopic ? descriptions($companyRequestTopic)->name : '',
            'request_type' => $this->request_type,
            'details' => $this->details,
            'requests' => $this->requests,
            'files' => $files,
        ];
    }
}
