<?php

namespace App\Http\Resources\V1;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Http\Resources\V1\ArtistListItemResource;

class ExhibitionListItemResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {

        $video    = new VideoResource($this->whenLoaded('video'));
        $gif      = new ImageResource($this->whenLoaded('gifImage'));
        $out = [
            'id'               => $this->id,
            'name'             => $this->title,
            'description'      => $this->description === null ? '' : $this->description,
            'pressReleaselink' => $this->press_release_link,
            'tags'             => TagResource::collection($this->whenLoaded('tags')),
            'image'            => new ImageResource($this->whenLoaded('image')),
            'gif_image'        => ($video->resource === null ?? $gif->resource) ? $gif : null,
            'video'            => $video->resource ? $video : null,
            'theme'            => $this->theme,
            'bgcolor'          => $this->bgcolor,
            'curator'          => $this->curator,
            'dateStatus'       => $this->date_status,
            'dateFrom'         => $this->date_from,
            'dateTo'           => $this->date_to,
            'highlight'        => $this->highlight,
            'sponsored'        => $this->sponsored,
            'location'         => new LocationResource($this->whenLoaded('location')),
            'artists'          => ArtistListItemResource::collection($this->whenLoaded('artists')),
            'share_url'        => $this->share_url,
        ];

        return $out;
    }
}
