<?php

namespace App\Http\Resources\Company;

use Illuminate\Http\Resources\Json\JsonResource;

class AvailableWorkers 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,
            'worker_type' => $this->worker_type,
            'rate' => $this->rate,
            'profile_picture' => $this->profile_picture,
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'experience_id' => $this->experience_id,
            'experience_name' => $this->experience_name,
            'is_draft' => 1,
            'profile_link' => $this->getProfileLink($this->profile_picture),
        ];
    }

    public function isBase64Profile($profilePicture){
        $wordToFind = 'data:image';
        return strpos($profilePicture, $wordToFind) !== false;
    }   

    public function getProfileLink($profilePicture){
        if(!$profilePicture){
            return null;
        }
        if($this->isBase64Profile($profilePicture)){
            return null;
        }
        return env('GOOGLE_CLOUD_LINK') .'/'. $this->profile_picture;
    }  
}
