<?php

namespace App\Http\Resources;


use Illuminate\Http\Resources\Json\JsonResource;
use DB;
use Auth;

class NotificationsResources extends JsonResource
{
    public function toArray($request)
    {

        $lang = $request->header('lang', '');


if(!empty($this->Safe()->first()->Name)){
    if($lang == 'ar'){
        $Safe=$this->Safe()->first()->Name;
    }else{
        $Safe=$this->Safe()->first()->NameEn;
    }
}else{
    $Safe='';

}

if(!empty($this->Store()->first()->Name)){
    if($lang == 'ar'){
        $Store=$this->Store()->first()->Name;
    }else{
        $Store=$this->Store()->first()->NameEn;
    }
}else{
    $Store='';

}



if(!empty($this->Client()->first()->Name)){
    if($lang == 'ar'){
        $Client=$this->Client()->first()->Name;
    }else{
        $Client=$this->Client()->first()->NameEn;
    }
}else{
    $Client='';

}
if(!empty($this->Product()->first()->P_Ar_Name)){
    if($lang == 'ar'){
        $Product=$this->Product()->first()->P_Ar_Name;
    }else{
        $Product=$this->Product()->first()->P_En_Name;
    }
}else{
    $Product='';

}

        if ($lang == 'ar') {
            $data = [
                'id'=>$this->id,
                'date'=>$this->Date,
                'notification'=>$this->Noti_Ar_Name,
                'client'=>$Client,
                'product'=>$Product,
                'store'=>$Store,
                'safe'=>$Safe,
            ];

        }else{

            $data = [
                'id'=>$this->id,
                'date'=>$this->Date,
                'notification'=>$this->Noti_En_Name,
                'client'=>$Client,
                'product'=>$Product,
                'store'=>$Store,
                'safe'=>$Safe,
            ];

        }
        return $data ;
    }

}
