<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\CategoryDescription;
use App\PageDescription;
use App\Models;
use App\Http\Resources\CityResource;
use App\Http\Resources\AreaResource;
use App\Http\Resources\NotificationResource;
use App\Http\Resources\SubscribeResource;

class MemberResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
     
    public function toArray($request)
    {
        
       
       
        $data =  [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'phone' => $this->phone,
            'photo' => asset('').$this->photo,
            'age' => $this->age,
            'gender' => $this->gender,
            'wallet' => $this->wallet,
            'money'  => (settings('points')*$this->wallet),
            'city'=>new CityResource($this->whenLoaded('city')),
            'area'=>new AreaResource($this->whenLoaded('area')),
            'notifications'=>NotificationResource::collection($this->whenLoaded('notifications')),
            'count_notifications' => count_notifications($this->id),
            'subscribed' => subscribed(),
            'nearsubscribe' => nearsubscribe(),
            'finishsubscribe' => finishsubscribe(),
            'subscribes'=>SubscribeResource::collection($this->whenLoaded('subscribes')),
            
            
            
            
            
      ];
      
      return $data;
    }
}
