<?php

namespace App\Http\Resources\Gallery;

use Illuminate\Http\Resources\Json\JsonResource;

class ImageItem extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $aws = app()->make('\App\Services\AWS');
        $out = [
            'uid'               => $this->uid,
            'originalFilename'  => $this->original_filename,
            'size'              => $this->file_size,
            'width'             => $this->width,
            'height'            => $this->height,
            'ratio'             => $this->width !== null && $this->height !== null ? $this->width / $this->height : 4 / 3,
            'key'               => $this->key,
            'thumb'             => $aws->getSignedUrl($aws->getThumbUrl($this->key, 800, 800, 'inside'))
        ];

        return $out;
    }
}
