<?php

namespace App\Http\Resources\Jobseeker;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\Company\Employeee\WorkerFiles;


class Account 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 parent::toArray($request);
        return [
            'id' => $this->id,
            'email_address' => $this->email_address,
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'phone_num' => $this->phone_num,
            'name' => $this->name,
            'address' => $this->address,
            'created_at' => $this->created_at,
            'street_address' => $this->street_address,
            'city' => $this->city,
            'state' => $this->state,
            'zipcode' => $this->zipcode,
            'distance' => $this->distance,
            'profile_picture' => $this->profile_picture,
            'availability_start_date' => $this->availability_start_date,
            'availability_end_date' => $this->availability_end_date,
            'resume' => $this->resume,
            'email_verified_at' => $this->email_verified_at,
            'jobseeker_work_area_lists' => $this->jobseeker_work_area_lists,
            'get_jobseeker_experiences' => $this->get_jobseeker_experiences,
            'resume_link' => $this->resume? env('GOOGLE_CLOUD_LINK') .'/'. $this->resume: null,
            'isBase64Profile' => $this->isBase64Profile($this->profile_picture),
            'profile_link' => $this->getProfileLink($this->profile_picture),
            'files' => WorkerFiles::collection($this->files),
        ];
    }

    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;
    }   
}
