<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class Gallery extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $data = [];
        #$data["id"] = $this->id;
        $data["name"] = $this->name;
        $data["created"] = $this->gallery_create_time;
        $data["url"] = [
            "name" => $this->url,
            "url" => url("/".$this->getTenant()->url."/".$this->url),
            "json" => url("/".$this->getTenant()->url."/".$this->url.".json"),
            ];
        $data["mainImage"] = [
            "id" => $this->main_image,
            "url" => [
                "small" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=small"),
                "medium" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=medium"),
                "big" => url("/".$this->getTenant()->url."/".$this->url."/".$this->main_image."/file?size=big")
            ]];
        $data["description"] = $this->description;
        $t = json_decode($this->tags);
        foreach ($t as $i => $g) {
            $t[$i] = trim($g);
        }
        $data["tags"] = $t;
        return $data;
    }
}
