<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class RestaurantResource 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,
        //     "name" => $this->name,
        //     "address" => $this->address,
        //     "city" => $this->city,
        //     "zip" => $this->zip,
        //     "slug" => $this->slug,
            
        // ];
        // soufian code
        $arr = [
            "name" => $this->name,
            "address" => $this->address,
            "city" => $this->horaire,
            "zip" => $this->telephone ?? '',
            "slug" => $this->slug,
            'markerIcon' => "images/map-marker.svg"
        ];

        if (is_array($this->getCoordinates())) {    
            $arr['coordinates'] = implode(',', $this->getCoordinates()[0]);
        }
        return $arr;
    }
}
