<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

use App\Http\Resources\MemberResource;
use App\Http\Resources\ConsultResource;
use App\Http\Resources\ChannelResource;



use App\Http\Resources\ExperienceResource;
use App\Http\Resources\CertificationResource;
use App\Http\Resources\RateResource;

class RateResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
     
    public function toArray($request)
    {
        
        if(getCurrentLocale() == 'ar'){
           $one = 'سئ جدا';
           $two = 'سئ';
           $three = 'مقبول';
           $four = 'جيد';
           $five = 'جيد جدا';
       }
       else{
            $one = 'so bad';
           $two = 'bad';
           $three = 'ok';
           $four = 'good';
           $five = 'very good ';
       }
       
        $data =  [
           'id' => $this->id,
           'rate' => $this->rate,
           'comment'=>$this->comment,
           'date'=>date('F j, Y',strtotime($this->created_at)),
           
           'member'=>new MemberResource($this->whenLoaded('member')),
           'consult'=>new ConsultResource($this->whenLoaded('consult')),
           'channel'=>new ChannelResource($this->whenLoaded('channel')),
            
            
            
            
            
      ];
      if($this->rate == '5'){
          $data_merge = [
              'title'=>$five,
              ];
      }
      elseif($this->rate == '4'){
           $data_merge = [
              'title'=>$four,
              ];
      }
        elseif($this->rate == '3'){
           $data_merge = [
              'title'=>$three,
              ];
      }
        elseif($this->rate == '2'){
           $data_merge = [
              'title'=>$two,
              ];
      }
        else{
           $data_merge = [
              'title'=>$one,
              ];
      }
      $data= array_merge($data, $data_merge);
      return $data;
    }
}
