<?php

namespace App\Http\Resources\V1;

use App\Http\Resources\V1\Blocks\BlockResource;
use Illuminate\Http\Resources\Json\JsonResource;

class CollectionResource extends JsonResource
{

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        $out = [
            'id'                       => $this->id,
            'name'                     => $this->title,
            'description'              => $this->description,
            'address_name'             => $this->address_name,
            'address'                  => $this->address,
            'website'                  => $this->website,
            'image_label'              => $this->image_label,
            'image'                    => new ImageResource($this->whenLoaded('image')),
            'explore_collection_image' => new ImageResource($this->whenLoaded('exploreCollectionImage')),
            'city'                     => new CityResource($this->whenLoaded('city')),
            'catalogue'                => new CollectionCatalogueResource($this->whenLoaded('catalogue')),
            'highlight'                => $this->highlight,
            'exhibitions'              => ExhibitionListItemResource::collection($this->whenLoaded('exhibitions')),
            'artists'                  => ArtistResource::collection($this->whenLoaded('artists')),
            'blocks'                   => [], //BlockResource::collection($this->whenLoaded('blocks')),
            'mapPositionLat'           => $this->map_position->latitude,
            'mapPositionLng'           => $this->map_position->longitude,
            'mapPositionZoom'          => $this->map_position_zoom,
            'share_url'                => $this->share_url,

        ];

        return $out;
    }
}
